If id found do... Else...
Posted: Tue Jun 17, 2008 9:03 am
I'm tearing my head of... I can't find the error...
I have a db table with alot of records. They all have a unique id (sponsor_id) but uid can be there several of times and so can the hole, but only once can the uid and hole be example uid=25 hole=1. Now what I want is to look through the script and look for a certain combination of uid and hole, and if it exists print out "ID FOUND". If it doesnt exist this combo it should go to the next line "NO ID FOUND". Everytime I run this script it shows "ID FOUND" even though the combo doesnt exists... Where do I go wrong?
I have a db table with alot of records. They all have a unique id (sponsor_id) but uid can be there several of times and so can the hole, but only once can the uid and hole be example uid=25 hole=1. Now what I want is to look through the script and look for a certain combination of uid and hole, and if it exists print out "ID FOUND". If it doesnt exist this combo it should go to the next line "NO ID FOUND". Everytime I run this script it shows "ID FOUND" even though the combo doesnt exists... Where do I go wrong?
Code: Select all
$result = mysql_query("SELECT * FROM sponsor WHERE uid='".$uid."' AND hole='".$hole."'");
while($row = mysql_fetch_array($result))
{
$id = $row['sponsor_id'];
}
if($id == $id) {
echo 'ID found: '.$id.''; }
elseif($id == 0) {
echo 'No ID found';
}