我運行的代碼存在問題。它引發這個錯誤,這裏給出:致命錯誤:未捕獲錯誤:調用成員函數在null中的查詢()
Fatal error: Uncaught Error: Call to a member function query() on null in /home/nissah5/sjs.vedantabgp.com/includes/functions.php:25 Stack trace: #0 /home/nissah5/sjs.vedantabgp.com/includes/batch.php(6): searchstudent() #1 /home/nissah5/sjs.vedantabgp.com/index.php(8): include('/home/nissah5/s...') #2 {main} thrown in /home/nissah5/sjs.vedantabgp.com/includes/functions.php on line 25
我寫的代碼是這裏。 第25行指$ query = $ db-> query($ query);
function searchstudent(){
connectdb();
$condition='1';
if(@$_GET['y']=='xii') $condition.=" and xii='".$_GET['yr']."'";
if(@$_GET['y']=='x') $condition.=" and x='".$_GET['yr']."'";
if(@$_GET['v']=='chapter') $condition.=" and chapter='".$_GET['chapter']."'";
$query="select name, x, xii, description, id from alumni where ".$condition;
echo $query;
$query=$db->query($query);
$row1=$query->fetchAll();
$query->closeCursor();
$i=1;
foreach ($row1 as $row){ $i=($i+1)%2; if($i==0){?>
<div class="row">
<div class="col-sm-5">
<img class="img-responsive" src="images/templatemo_image_4.jpg" alt="image 4" />
</div>
<?php searchrow($row);} else{ ?>
<div class="col-sm-1"></div>
<div class="col-sm-5">
<img class="img-responsive" src="images/templatemo_image_5.jpg" alt="image 5" />
</div>
<?php searchrow($row);?>
</div>
<?
}
}
if ($i==0) echo "</div>";
}
回聲給出了這樣的結果
select name, x, xii, description, id from alumni where 1
https://secure.php.net/variables.scope !!! –
謝謝你的問題(y) –