Jump to content

Archived

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

pwdrskier4

loop help please!

Recommended Posts

Hi, I am having trouble with this. I have two tables that both have a primary key named 'myid'. Basically, I am trying to loop through the rows of the first table and check to see if a row with the primary key of the same value exist in the second table. Here is what I have so far but it is not working properly.


[code]<?php

do {
$check = $row_Recordset1['table1_id'];
if ($row_Recordset2['table2_id'] == $row_Recordset1['table1_id']){
echo "$check exists in table 2<br />";

}
else {echo "$check does not exist in table 2<br />";}
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));

echo "<br />Done <br />";
?>[/code]

Share this post


Link to post
Share on other sites
Why dont you use joins :

select * from table1,table2 where table1_id=table2_id


, it will return only the records where the ids are present in both the tables.

Share this post


Link to post
Share on other sites

×

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.