JJohnsenDK Posted December 15, 2006 Share Posted December 15, 2006 The code doesnt print/echo the variable in the while loops, why?There are two loops, this:[code]//Hent farver på tøjet $get_color = "SELECT `item_color` FROM `store_item_color` WHERE `item_id` = '$item_id' ORDER BY `item_color`"; $get_color_res = mysql_query($get_color) or die(mysql_error()); if (mysql_num_rows($get_color_res) < 0){ $display_block .= "<p><strong>Farver tilgængelig:</strong><br>"; while($colors = mysql_fetch_array($get_color_res)){ $item_color = $colors['item_color']; $display_block .= "$item_color<br>"; print "Test"; } }[/code]And the get_size. Only thing it should do is to print the text there is in the database colum item_color.The table for store_item_color has two colums item_id and item_color and the same does for the table store_item_size, it has item_id and item_size.The whole code is here:[code]<?php//Forbindelse til MySQL databaseinclude('config.php');//Visning af overskrift$display_block = "<h2>Katrinelund online butik - Varer detaljer</h2>";$get_item = "SELECT c.cat_title, si.item_title, si.item_price, si.item_desc, si.item_image FROM store_items as si LEFT JOIN store_categories AS c ON c.id = si.cat_id WHERE si.id = $_GET[item_id]";$get_item_res = mysql_query($get_item) or die(mysql_error());if (mysql_num_rows($get_item_res) < 1){ //Hvis der ikke eksistere en item/varer $display_block .= "Det er i øjeblikket ikke muligt at få forbindelse til serveren.";}else{ //Hvis varen eksistere $cat_title = strtoupper(stripslashes(mysql_result($get_item_res,0,'cat_title'))); $item_title = stripslashes(mysql_result($get_item_res,0,'item_title')); $item_price = mysql_result($get_item_res,0,'item_price'); $item_desc = stripslashes(mysql_result($get_item_res,0,'item_desc')); $item_image = mysql_result($get_item_res,0,'item_image'); //Vejlende navigation $display_block .= " <p><strong><em>Du ser på:</em><br><a href=\"main.php?cat_id=$cat_id\">$cat_title</a></strong> > $item_title</p> <table> <tr> <td valign=\"middel\" align=\"center\"><img src=\"$item_image\"></td> <td valign=\"top\"> <P><strong>Beskrivelse:</strong><br>$item_desc</p> <P><strong>Pris:</strong>$item_price dkr.</p>"; //Hent farver på tøjet $get_color = "SELECT `item_color` FROM `store_item_color` WHERE `item_id` = '$item_id' ORDER BY `item_color`"; $get_color_res = mysql_query($get_color) or die(mysql_error()); if (mysql_num_rows($get_color_res) < 0){ $display_block .= "<p><strong>Farver tilgængelig:</strong><br>"; while($colors = mysql_fetch_array($get_color_res)){ $item_color = $colors['item_color']; $display_block .= "$item_color<br>"; print "Test"; } } //Hent størrelser på tøjet S, M, L osv. $get_size = "SELECT `item_size` FROM `store_item_size` WHERE `item_id` = '$item_id' ORDER BY `item_size`"; $get_size_res = mysql_query($get_size) or die(mysql_error()); if (mysql_num_rows($get_size_res) < 0){ $display_block .= "<p><strong>Størrelser tilgængelig:</strong></p>"; while($size = mysql_fetch_array($get_size_res)){ $item_size = $size['item_size']; $display_block .= "$item_size<br>"; } } $display_block .=" </td> </tr> </table> ";}?><HTML><HEAD><TITLE>Katrinelund Onlinebutik</TITLE></HEAD><BODY><? print $display_block; ?></BODY></HTML>[/code]Hope someone can help have been looking through this code soooo many times now :-[ Link to comment https://forums.phpfreaks.com/topic/30742-why-wont-this-while-loop-echo-to-browser/ Share on other sites More sharing options...
JJohnsenDK Posted December 15, 2006 Author Share Posted December 15, 2006 Anyone? Link to comment https://forums.phpfreaks.com/topic/30742-why-wont-this-while-loop-echo-to-browser/#findComment-141720 Share on other sites More sharing options...
obsidian Posted December 15, 2006 Share Posted December 15, 2006 Well, what I noticed right off the bat is that you're seeing if there were [b]less than zero[/b] records returned. Try changing up the sign you're using:[code]<?php// Change this:if (mysql_num_rows($get_color_res) < 0)// to this:if (mysql_num_rows($get_color_res) > 0)?>[/code]Good luck! Link to comment https://forums.phpfreaks.com/topic/30742-why-wont-this-while-loop-echo-to-browser/#findComment-141730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.