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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 11, 2007 Share Posted July 11, 2007 What that echo in such a form? Quote Link to comment 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()) Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.