blueman378 Posted June 4, 2008 Share Posted June 4, 2008 hi guys, well heres the code *snippet* public function view_prod($cid) // ADD A NEW PRODUCT { echo "<table border=\"1\"> <tr> <td><strong>Product Name</strong></td> <td><strong>Product Description</strong></td> <td><strong>Product Picture</strong></td> <td><strong>Product Price</strong></td> <td><strong>Product Instock</strong></td> <td><strong>Product Category</strong></td> <td><strong>Actions</strong></td> </tr> "; if(isset($cid) && $cid != 0) { $query = mysql_query("SELECT * FROM products WHERE cid='$cid'") or die(mysql_error()); } else { $query = mysql_query("SELECT * FROM products") or die(mysql_error()); } while ($products = mysql_fetch_array($query)) { echo " <tr> <td valign=\"top\">$products[Name]</td> <td valign=\"top\">$products[Description]</td> <td valign=\"top\"><a href=\"../pictures/Fulls/$products[image]\"> <img border=\"0\" src=\"../pictures/Thumbs/$products[image]\"></a></td> <td valign=\"top\">$products[Cost]</td> <td valign=\"top\">$products[Quantity]</td>"; $query = mysql_query("SELECT * FROM sub_categories WHERE id='$products[cid]'") or die(mysql_error()); $row = mysql_fetch_assoc($query); $subcat = $row[Name]; $query = mysql_query("SELECT * FROM main_categories WHERE id='$row[mid]'") or die(mysql_error()); $row = mysql_fetch_assoc($query); $maincat = $row[Name]; echo"<td valign=\"top\">$maincat >> $subcat</td> <td valign=\"top\">none</td> </tr> "; } echo "</table>"; } so it should echo eg all prodcuts from fruit when you select the fruit category but it is only echoing one result and then stopping, any ideas? Link to comment https://forums.phpfreaks.com/topic/108681-solved-only-echoes-one-result/ Share on other sites More sharing options...
phpzone Posted June 4, 2008 Share Posted June 4, 2008 Looks like your reusing your $query variable. The inner mysql lookups need their own variables. Link to comment https://forums.phpfreaks.com/topic/108681-solved-only-echoes-one-result/#findComment-557309 Share on other sites More sharing options...
Wolphie Posted June 4, 2008 Share Posted June 4, 2008 They don't need their own variables, they can be re-used time and time again. I can see one problem: $products[Name] The declaration of array key's should contain quotes if it's a string. Otherwise PHP will iterate through every possible key, and when it doesn't exist it will finally determine that the key you gave it is in fact a string. A long process Link to comment https://forums.phpfreaks.com/topic/108681-solved-only-echoes-one-result/#findComment-557330 Share on other sites More sharing options...
phpzone Posted June 4, 2008 Share Posted June 4, 2008 $query is defined before this loop: while ($products = mysql_fetch_array($query)) { ... ... } And within the loop $query is overwritten, invalidating the original query. Link to comment https://forums.phpfreaks.com/topic/108681-solved-only-echoes-one-result/#findComment-557352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.