dongtan9465 2016-05-17 02:14
浏览 25
已采纳

PHP:while循环没有显示db问题中的所有结果

I am having a problem getting my query to fetch all the results needed from my DB. I have a search on my home page, which directs the user to the page i am discussing. The user uses their postal code to search for restaurants in their area.

My query checks the db for results that match what has been inputted into the search bar, my problem is it only shows 1 result even if their are more than one. It always shows the last restaurant inputted into the DB.

I cannot seem to see what the problem is, any help or suggesting would be much appreciated.

 $output='';
  if(isset($_POST['search'])){
$searchq= $_POST['search'];


             $sql=mysqli_query($dbc,"SELECT *
 FROM Rest_Details 
 WHERE Delivery_Pcode.Pcode LIKE '%".$searchq."'") or die ("could not search!");
             echo var_dump($sql);

             $count = mysqli_num_rows($sql);
             if($count ===0){
$output ='<b>Oh no! We do not currently deliver to '.$searchq.'</b></br>
                    Please leave your email address & we will notify you as soon as we do! </br>
<form action="Area_Rest_page.php">
<input type="text" name="FirstName" value="">
<input type="submit" value="Submit">
</form>';

             }else{
                 $i=1;
             }while($row_prods=  mysqli_fetch_array($sql)){
            $EXAMPLE = $row_prods['EXAMPLE'];


            $output ='<h3 id="rest_name">'.$rest_name .'</h3>'.

                     ;    
            $i++;

Then the following is placed further down the page.

print("$output");

The DB and successfully connected,session has been started, i also have error handlers (no errors)

  • 写回答

1条回答 默认 最新

  • douyi2107 2016-05-17 03:12
    关注

    Same as Bender suggested but you can not use (+) sign for concatenation, use (.) instead.

    $output = $output . '<h3 id="rest_name">'.$rest_name .'</h3>'.
                        '<p class="title"> Price</p>'.
                        '<p class="title">Avg Delivery</p>'.
                        '<p class="title">Cost</p>'. 
                        '<a href="product_page.php?rest_id='.$rest_id.'&Postcode='.$searchq.'"><button id="feed">Feed Me!</button></a>'.
                         ; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试