jscix Posted February 21, 2007 Share Posted February 21, 2007 Ok im having a bit of a problem, This code works.. however, when it finds multiple entries, it is only returning the first one (first row I guess?) How can I get this to find all the rows, and move on to the next one after putting the data into vars? <?php $connection = mysql_connect("mysql", "lllll", "lllll"); if (!$connection) { print "Failed to connect to database";} $db_select = mysql_select_db("posts"); if (!$db_select) { print "Failed to find database";} $sendsql = " SELECT * FROM comments WHERE tou IN ( '$curusr' ) LIMIT 0 , 30 "; $sqlq = mysql_query($sendsql); if (!$sqlq) { print "Failed to find"; die();} $dbdata = mysql_fetch_row(($sqlq)); $postid = $dbdata[0]; // post ID $retuidz = $dbdata[1]; //from user $retusrn = $dbdata[2]; // to user $retcom = $dbdata[3]; //comment print_r ($dbdata); ?> Link to comment https://forums.phpfreaks.com/topic/39559-solved-retrieving-multiple-rows-from-a-table/ Share on other sites More sharing options...
jscix Posted February 21, 2007 Author Share Posted February 21, 2007 hrmm, what I mean is, After I use mysql_fetch_row, and it returns the data from the first-row into the variables, how do I get it to retrive the next row, it seems to only be grabbing the first one every time.. Link to comment https://forums.phpfreaks.com/topic/39559-solved-retrieving-multiple-rows-from-a-table/#findComment-190881 Share on other sites More sharing options...
jcbarr Posted February 21, 2007 Share Posted February 21, 2007 fetch_row is only designed to fetch one row. Try using a while loop with mysql_fetch_array. That should work better for you. Something like this. while ($dbdata=mysql_fetch_array($sqlq)) { //echo the values here } Link to comment https://forums.phpfreaks.com/topic/39559-solved-retrieving-multiple-rows-from-a-table/#findComment-190886 Share on other sites More sharing options...
jscix Posted February 22, 2007 Author Share Posted February 22, 2007 Oh nice, Tyvm! Link to comment https://forums.phpfreaks.com/topic/39559-solved-retrieving-multiple-rows-from-a-table/#findComment-190899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.