您好我目前有php語句中的if語句與準備語句有關的問題,無論我在檢查get_result時輸入什麼內容,我的語句總是如此。我真的不知道我在做什麼,我對PHP和準備語句的概念非常陌生。PHP檢查在if語句中準備好的語句
$searchtext= $_POST['search-box'];
$sqlName= $connect->prepare("SELECT * FROM SearchPG WHERE PGName LIKE ? ");
$sqlName->bind_param("s", $searchtext);
$sqlName->execute();
$NameResult = $sqlName->get_result();
$sqltext= $connect->prepare("SELECT * FROM SearchPG WHERE PGKeywords LIKE ? ");
$sqltext->bind_param("s", $searchtext);
$sqltext->execute();
$TextResult = $sqltext->get_result();
if($NameResult->num_rows > 0 || $TextResult->num_rows > 0){
if($NameResult->num_rows > 0){
echo "made it into sqlname";
while($rs = $NameResult->fetch_assoc()){
echo "name result";
?>
<div class="row resultcontent">
<a href="<?php echo $rs['PGUrl'];?>">
<div class="col-sm-8 searchRsltCont">
<img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
<div class="contshading">
</div>
</div>
<div class="col-sm-4 searchRslttxt">
<h1><?php echo "name".$rs['PGName'];?></h1>
</div>
</a>
</div>
<?php
$count++;
}
}
if($count<10){
echo "exploded result";
foreach($searchbit as $value){
$temp = '%'.$value.'%';
$sqlvalue= $connect->prepare("SELECT * FROM SearchPG WHERE PGName LIKE ? OR PGKeyword LIKE ? ");
$sqlvalue->bind_param("ss", $temp, $temp);
$sqlvalue->execute();
$ValueResult = $sqlvalue->get_result();
if($ValueResult->num_rows > 0){
while($rs = $ValueResult->fetch_assoc()){
?>
<div class="row resultcontent">
<a href="<?php echo $rs['PGUrl'];?>">
<div class="col-sm-8 searchRsltCont">
<img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
<div class="contshading">
</div>
</div>
<div class="col-sm-4 searchRslttxt">
<h1><?php echo "name".$rs['PGName'];?></h1>
</div>
</a>
</div>
<?php
$count++;
}
}
}
while($rs = $TextResult->fetch_assoc()){
?>
<div class="row resultcontent">
<a href="<?php echo $rs['PGUrl'];?>">
<div class="col-sm-8 searchRsltCont">
<img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
<div class="contshading">
</div>
</div>
<div class="col-sm-4 searchRslttxt">
<h1><?php echo "name".$rs['PGName'];?></h1>
</div>
</a>
</div>
<?php
$count++;
}
}
我都試過,如果(!$結果),如果($ result-> NUM_ROWS> 0),如果($ result-> affected_rows)等,但似乎沒有任何工作有任何人有任何想法我什麼我做錯了
對不起,但請將「代碼牆」縮短爲展示此問題的最小示例。沒有人想要完成所有這些工作。 – arkascha
@arkascha對不起,我清理它 – noob