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.
Here's my code (including code to test variable values):
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)) { print_r($row); echo ("id = ".$row[$i][0].", "); $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); if( ! empty($rowrating)) printf("Rating: %s", $rowrating[1]); $i = $i+1; } ?>
Any help is most appreciated.
Thanks
Paul




Bookmarks