maxxtraxx Posted July 11, 2007 Share Posted July 11, 2007 total newbie question here, so save your jeers until after you solve my prob. i have a table of products that i just want to loop over using a while() yet i only get one row. here's what i'm doing. <?php include("includes/connx.php"); $url = $_SERVER['QUERY_STRING']; $sql = 'SELECT * FROM products p, productGroups g WHERE p.group_id = g.group_id AND p.'.$url ; $groups = mysql_query($sql, $dbh) or die (mysql_error()); $row_groups = mysql_fetch_assoc($groups); ?> <?php while($row = mysql_fetch_array($groups)){ echo ($row['name'] . "<br />"); } ?> i think it might be the mysql_fetch_assoc() that is limiting it, but i'm not really sure what that does to be honest... as you can see i'm just getting beyond the basics and its a mighty deep pool here. any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/ Share on other sites More sharing options...
suma237 Posted July 11, 2007 Share Posted July 11, 2007 $row_groups = mysql_fetch_assoc($groups);---remove this Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/#findComment-295065 Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 If you're only getting one row then check your MySQL query and make sure it should be reporting more - check in cPanel if you're running online or have it installed on your PC. As for the line suma has pointed out - remove it. If your query is only returning two results then having that extra line will be "disabling" the first row and you'll be seeing the second row onwards. Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/#findComment-295084 Share on other sites More sharing options...
rameshfaj Posted July 11, 2007 Share Posted July 11, 2007 Are u sure that ur query returned more than one rows? Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/#findComment-295101 Share on other sites More sharing options...
rameshfaj Posted July 11, 2007 Share Posted July 11, 2007 What that echo in such a form? Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/#findComment-295102 Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 $row_groups = mysql_fetch_assoc($groups); Remove that line and try again (it's immediately before while()) Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/#findComment-295103 Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 <?php include("includes/connx.php"); $url = $_SERVER['QUERY_STRING']; $sql = 'SELECT * FROM products p, productGroups g WHERE p.group_id = g.group_id AND p.'.$url ; $groups = mysql_query($sql, $dbh) or die (mysql_error()); $row_groups = mysql_fetch_assoc($groups); while ($row = mysql_fetch_array($groups)) { echo $row['name'] . "<br />"; } ?> I've removed the line for you. If you post your code between [code] and [/code] tags it makes it a lot easier to read. Link to comment https://forums.phpfreaks.com/topic/59396-while-problems/#findComment-295105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.