pwdrskier4 Posted May 31, 2006 Share Posted May 31, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10810-loop-help-please/ Share on other sites More sharing options...
samshel Posted May 31, 2006 Share Posted May 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10810-loop-help-please/#findComment-40462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.