A combo query retreiving data from database

 Question:


I have 2 tables:
sent & profile

I store emails in sent, and when i echo them, i want to if each email already exists in profile

So, i did this:

Code:
$q = "SELECT * FROM sent ORDER BY date_sent DESC, time_sent DESC LIMIT 50;";

$res = @mysql_query($q);

while($r = @mysql_fetch_array($res))
{
$IsHeMember==$r[email_sent];
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Nickname:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#000000\" face=\"Arial\">$r[nickname_sent]</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Profile ID:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
echo "<a href='/ads/results/one.php?ID={$r['profile_sent']}' target='_blank'>$r[profile_sent]</a>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Email:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#000000\" face=\"Arial\">$r[email_sent]</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Date:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#000000\" face=\"Arial\">$r[date_sent]</FONT>";

$q2 = "SELECT * FROM profile WHERE Email='$IsHeMember'";
$res = @mysql_query($q2);

if(mysql_num_rows($res)>0){
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#009300\" face=\"Arial\">Member</FONT>";
}else{
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#FF0000\" face=\"Arial\">Not Member</FONT>";
}

print "<br>";

}


but somehow, this code only shows the results which meet both conditions
I.e. only the results where the email is in both sent & profile

I want to shows all rows from sent, and to check the email in profile

Hope i am understandable, Very Happy
 




 Answers:
 


Rename the second variable $res = @mysql_query($q2); to $res1 = @mysql_query($q2);


Your code can be something like this:


Code:
<?
$q = "SELECT * FROM sent ORDER BY date_sent DESC, time_sent DESC LIMIT 50;";

$res = @mysql_query($q);

while($r = @mysql_fetch_array($res))
{
$IsHeMember==$r[email_sent];
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Nickname:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#000000\" face=\"Arial\">$r[nickname_sent]</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Profile ID:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
echo "<a href='/ads/results/one.php?ID={$r['profile_sent']}' target='_blank'>$r[profile_sent]</a>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Email:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#000000\" face=\"Arial\">$r[email_sent]</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#0080FF\" face=\"Arial\">Date:</FONT>";
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#000000\" face=\"Arial\">$r[date_sent]</FONT>";

$q2 = "SELECT * FROM profile WHERE Email='$IsHeMember'";
$res1 = @mysql_query($q2);

if(mysql_num_rows($res1)>0){
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#009300\" face=\"Arial\">Member</FONT>";
}else{
print "<FONT style=\"font-size:5px\" color=\"#FFFFFF\" face=\"Arial\">...............</FONT>";
print "<FONT style=\"font-size:12px\" color=\"#FF0000\" face=\"Arial\">Not Member</FONT>";
}

print "<br>";

}

?>


Commentaires

Posts les plus consultés de ce blog

XAJAX with PHP – The future of web development

XAJAX with PHP – The future of web development

Database connection pooling in ADO.Net