tikiman Posted August 7, 2008 Share Posted August 7, 2008 <?php //Select statement to be sent to MYSQL Database ordered by title $query = "SELECT * FROM `products` WHERE title = 'title1' ORDER BY item_num"; //Result set from the MYSQL Query $result = mysql_query($query) or die(mysql_error()); //Counter to keep track of how many displayed $count = 1; //Initiate the table to hold the items echo "<table><tr>"; //While Loop to fetch and display all the products in nested tables while($newArray = mysql_fetch_array($result, MYSQL_ASSOC)) { //All the columns of the table in the database $item_num = $newArray['item_num']; $units_per_case = $newArray['units_per_case']; $pieces_per_unit = $newArray['pieces_per_unit']; $weight = $newArray['weight']; $section = $newArray['section']; $title = $newArray['title']; $desc = $newArray['desc']; $image_id = $newArray['image_id']; //If there are less than 3 items in the table it adds the next item to it if($count <= 3) { //Prints out the rows and columns in the table echo " <td> <table width='210'> <tr> <td height='70'> "; $filename = "images/products/new/$image_id.png"; if (file_exists($filename)) { echo "<a class='popup' href='#'><img src='images/products/new/$image_id.png'><span><img src='images/products/big/$image_id.png'></span></a>"; } else { echo "<img src='images/products/new/holder.png'>"; } echo " </td> </tr> <tr> <td>item # $item_num</td> </tr> <tr> <td>$desc</td> </tr> </table> </td> "; $count++; } else if($count > 3) { //Closes the table and starts a new one when there are more than 3 items in the current table $count = 1; echo "</tr>"; echo "</table>"; echo "<br>"; echo "<table>"; echo "<tr>"; } } if($count = 1) { //Closes the empty table that is created when there are only 3 left echo "</tr>"; echo "</table>"; echo "<br>"; } ?> Some of the items are not being displayed, usually 1 per title, any ideas why? Link to comment https://forums.phpfreaks.com/topic/118707-not-all-items-are-being-displayed-from-mysql-db/ Share on other sites More sharing options...
elflacodepr Posted August 7, 2008 Share Posted August 7, 2008 I can't see anywhere in your code that you connected to DB or include any file to do so. Here is: <?php //DB Config $user = 'user here'; $pass = 'password here'; $host = 'localhost'; $dbname = 'Data Base name here'; // Connect to DB $db = mysql_connect ($host, $user, $pass) or die ('Error: ' . mysql_error()); mysql_select_db ($dbname); //Select statement to be sent to MYSQL Database ordered by title $query = "SELECT * FROM `products` WHERE title = 'title1' ORDER BY item_num"; //Result set from the MYSQL Query $result = mysql_query($query) or die(mysql_error()); //Counter to keep track of how many displayed $count = 1; //Initiate the table to hold the items echo "<table><tr>"; //While Loop to fetch and display all the products in nested tables while($newArray = mysql_fetch_array($result, MYSQL_ASSOC)) { //All the columns of the table in the database $item_num = $newArray['item_num']; $units_per_case = $newArray['units_per_case']; $pieces_per_unit = $newArray['pieces_per_unit']; $weight = $newArray['weight']; $section = $newArray['section']; $title = $newArray['title']; $desc = $newArray['desc']; $image_id = $newArray['image_id']; //If there are less than 3 items in the table it adds the next item to it if($count <= 3) { //Prints out the rows and columns in the table echo " <td> <table width='210'> <tr> <td height='70'> "; $filename = "images/products/new/$image_id.png"; if (file_exists($filename)) { echo "<a class='popup' href='#'><img src='images/products/new/$image_id.png'><span><img src='images/products/big/$image_id.png'></span></a>"; } else { echo "<img src='images/products/new/holder.png'>"; } echo " </td> </tr> <tr> <td>item # $item_num</td> </tr> <tr> <td>$desc</td> </tr> </table> </td> "; $count++; } else if($count > 3) { //Closes the table and starts a new one when there are more than 3 items in the current table $count = 1; echo "</tr>"; echo "</table>"; echo "<br>"; echo "<table>"; echo "<tr>"; } } if($count = 1) { //Closes the empty table that is created when there are only 3 left echo "</tr>"; echo "</table>"; echo "<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/118707-not-all-items-are-being-displayed-from-mysql-db/#findComment-611185 Share on other sites More sharing options...
tikiman Posted August 7, 2008 Author Share Posted August 7, 2008 I have seperate config, open, and close files for my db located elsewhere and they are all included on another seperate php page Link to comment https://forums.phpfreaks.com/topic/118707-not-all-items-are-being-displayed-from-mysql-db/#findComment-611189 Share on other sites More sharing options...
moselkady Posted August 8, 2008 Share Posted August 8, 2008 Could you post the output the you get and also the output that you want to see? Link to comment https://forums.phpfreaks.com/topic/118707-not-all-items-are-being-displayed-from-mysql-db/#findComment-611222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.