When I am trying to run a while loop to determine if one of the (many) email addresses inside my "table_1" match any of the email addresses inside my "table_2". But it did not work .Hersr is my code :

while($row2 = mysql_fetch_array($get_names2_res)) { 
while($row = mysql_fetch_array($get_names_res)) { 

  $friend_email = stripslashes($row['friend_email']);
  $users_email = stripslashes($row2['email']);
  
  if ($users_email == $friend_email) {
  
  echo"Yeah we found that name ($users_email)";
       
  }
}

}

It only reads one email at a time, but what I need is to read all the emails at one time.
Can any one help me ?

Hi,
With while we can read only row by row. Anyways, it seems you want to search the email into friend_email. Another alternative would be query the friends email table for each email.

In any case please use the following sequence for performance improvement.

while($row2 = mysql_fetch_array($get_names2_res)) {

$users_email = stripslashes($row2['email']);
 
while($row = mysql_fetch_array($get_names_res)) {
...}}

References:
http://www.tutorialindia.com/php/php_looping.php#while
http://www.tutorialindia.com/php_mysql/php_mysql_select.php

hanks for the reply. I will try it .

But...man , It still does work to my exceptions. I don't need a number of emails, I need to know if a specific email address is inside both MYSQL tables.What should I do ? Any tips ?

Hi,

I have some questions.
1. If you have that specific email that you want search then you can search that using sql query.
like

select email from table1,table2 where table1.id = table2.id and (table1.email=email1 or table2.email = email1)

2. if you don't have emailid's and you want to find out the common emailid's in two tables then

select email from table1,table2 where table1.id = table2.id

If your requirement is different then give your requirement in detail.

What exactly are you trying to do ? Because, earlier you said,

When I am trying to run a while loop to determine if one of the (many) email addresses inside my "table_1" match any of the email addresses inside my "table_2".

Now you are saying,

I don't need a number of emails, I need to know if a specific email address is inside both MYSQL tables.

Can you be more specific ?

sorry ,combine your advice,now I just try

SELECT friend_e_mail FROM my_table WHERE friend_email NOT IN ( SELECT email FROM my_table )

/*A little note. This SQL checks on the same table if the e-mails in friend columns are also in e-mail column. If have 2 separate tables, do it like this * /

SELECT friend_e_mail FROM my_table WHERE friend_email NOT IN ( SELECT email FROM my__other_table )

Is that right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.