Jump to content

[help] WHILE loop or not?


csj

Recommended Posts

I think I need to use something else besides a while loop with this problem I have. I'm just not sure what.

 

I'm trying to run a while loop so I can determine if one of the (many) email addresses inside my "table_1" match any of the email addresses inside my "table_2". And if it does then I need to delete that row from table_1.

 

But it won't work!!

 

I must be doing something wrong or maybe I shouldn't even be using a WHILE loop. Can someone help me with this. I would be so happy and grateful!!  ;D ;D ;D

 

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 works but not how I want it to work. It only reads one email at a time and I need it to read all the emails at one time.

Link to comment
Share on other sites

Best solution is to pull the contents of both databases into an array and then compare them.

 

You're just over thinking this one.

 

Basically (not tested, general idea):

<?php
while($row = mysql_fetch_assoc($get_names_res))
{
    $user_email[] = $row['email'];
}

unset($row);

while($row = mysql_fetch_assoc($get_names2_res))
{
    $friend_email[] = $row['friend_email'];
}

$total_user = count($user_email)

for($i = 0; $i < $total_user; ++$i)
{
   if(in_array($friend_email[$i], $user_email)
   {
      echo 'Found one!';
   }
   else
   {
      echo 'Didn't find one!';
   }

}

Link to comment
Share on other sites

Thanks for the replies!!! :D

 

With what awpti said, how would I then be able to delete that specific row from my database. The row that matches the email address?

 

Thanks for all the help :D :D :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.