Page 1 of 1

Loop array problem

Posted: Sun Feb 01, 2009 2:49 pm
by cap2cap10
How do I loop array data from two mysql tables?

Code: Select all

$query  = "SELECT candidateID, category, degree, years_exp, work_time, available FROM js_db1";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
    {$row['candidateID']} <br>" .
    {$row['category']} <br>" .
    {$row['degree']} <br><br>";
    {$row['years_exp']}
    {$row['work_time']}
    {$row['available']}
}
$query  = "SELECT image_name FROM js_db2 WHERE candidateID = '?'";
$result = mysql_query($query);
any takers?

Thanks in advance

Batoe

You can get "there" from "here", If you know where "there" is!

Re: Loop array problem

Posted: Sun Feb 01, 2009 2:56 pm
by John Cartwright
You should generally avoid nested queries. In this case, you can join the two queries together.

Code: Select all

$query  = "
   SELECT candidateID, category, degree, years_exp, work_time, available 
   FROM js_db1
   INNER JOIN js_db2 ON js_db2.candidateID = js_db1.candidateID
";