Jump to content


Photo

loop help please!


  • Please log in to reply
1 reply to this topic

#1 pwdrskier4

pwdrskier4
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 May 2006 - 12:41 AM

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.


<?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 />";
?>


#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 31 May 2006 - 06:02 AM

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.
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users