Jump to content

Help needed with PHP While loop and MySQL


adders

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.