Jump to content

only getting one row?


justinh

Recommended Posts

<div id=\"navbar\">
         Select A Category
        </div>
       <div id=\"items\">";
       $get_cats = mysql_query("SELECT * FROM tbl_category");
       while($cats = mysql_fetch_array($get_cats)){
       echo "<div id=\"category\" onclick=\"location.href=default.php?catid".$cats['cat_id'].";\"><b>".$cats['cat_name']."</b><br>
       <small>".$cats['cat_description']."</small></div></div></div></body></html>";
       }

 

Theres 5 categories in tbl_category,

 

but for some reason: (only one is showing up)

 

http://www.wmptest.com/clintormscart/default.php

 

hmmm..  any ideas?

Link to comment
https://forums.phpfreaks.com/topic/136090-only-getting-one-row/
Share on other sites

Actually all five are being displayed. It's your HTML that is causing the problem. The following highlighted code should be outside of your while loop:

<div id=\"navbar\">

        Select A Category

        </div>

      <div id=\"items\">";

      $get_cats = mysql_query("SELECT * FROM tbl_category");

      while($cats = mysql_fetch_array($get_cats)){

      echo "<div id=\"category\" onclick=\"location.href=default.php?catid".$cats['cat_id'].";\"><b>".$cats['cat_name']."</b><br>

      <small>".$cats['cat_description']."</small></div></div></div></body></html>";

      }

 

Fixed code:

 <div id=\"navbar\">
         Select A Category
        </div>
       <div id=\"items\">";

$get_cats = mysql_query("SELECT * FROM tbl_category");
while($cats = mysql_fetch_array($get_cats))
{
    echo "<div id=\"category\" onclick=\"location.href=default.php?catid".$cats['cat_id'].";\"><b>".$cats['cat_name']."</b><br>
             <small>".$cats['cat_description']."</small></div>\n";
}
echo "</div></div></body></html>";

Link to comment
https://forums.phpfreaks.com/topic/136090-only-getting-one-row/#findComment-709610
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.