adders Posted February 20, 2007 Share Posted February 20, 2007 Hello Guys This is giving me a real headache, I'm no PHP or MYSQL expert and I'm just baffled. I'm trying to query to one table to pull out data that I will then use to query a second table. In my test I expect rows 3 & 4 to be obtained. This works fine for the first loop, giving me row 3, but then instead of row 4 the loop outputs row 1, any ideas? I suspect that it is something to do with the While loop as when I use print_r() to output the array I'm looping it outputs the correct data. Code: <?php $dbhost = 'localhost'; $dbuser = 'root'; $conn = mysql_connect($dbhost, $dbuser) or die ('Error connecting to mysql'); $dbname = 'implit'; mysql_select_db($dbname); $i = 0; $query = "SELECT * FROM `jos_jreviews_comments` WHERE pid='15'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $queryrating = "SELECT * FROM `jos_jreviews_ratings` WHERE reviewid=".$row[$i][0].""; $resultrating = mysql_query($queryrating) or die(mysql_error()); $rowrating = mysql_fetch_array($resultrating, MYSQL_NUM); printf("Rating: %s", $rowrating[1]); $i = $i+1; } ?> Any help is most appreciated. Thanks Paul Link to comment https://forums.phpfreaks.com/topic/39282-help-needed-with-php-while-loop-and-mysql/ Share on other sites More sharing options...
skali Posted February 20, 2007 Share Posted February 20, 2007 $queryrating = "SELECT * FROM `jos_jreviews_ratings` WHERE reviewid=".$row[0].""; if the index of your field reviewid in database table is 0 Link to comment https://forums.phpfreaks.com/topic/39282-help-needed-with-php-while-loop-and-mysql/#findComment-189338 Share on other sites More sharing options...
adders Posted February 20, 2007 Author Share Posted February 20, 2007 Thanks Skali - that worked. Man - I swear I tried that one out ages ago. Thanks again mate. Cheers Paul Link to comment https://forums.phpfreaks.com/topic/39282-help-needed-with-php-while-loop-and-mysql/#findComment-189370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.