Loop array problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Loop array problem

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Loop array problem

Post 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
";
Post Reply