Brendan Nolan
02-12-2003, 10:04 PM
Hi... me again!!
Pulling stuff from a databese. I am inside a while loop set up like so...
while ($myrow = mysql_fetch_array($result)){
then inside it I am doing a few SQL things to get some contact details from a table...
$contactsql = "SELECT phone, mobile_phone, after_hours_phone, fax FROM people WHERE person_id = '$persid' AND person_name = 'Main'";
$contactresult = mysql_query($contactsql);
$pphone = mysql_result($contactresult,"phone");
$pmob = mysql_result($contactresult,"mobile_phone");
$pah = mysql_result($contactresult,"after_hours_phone");
$pfax = mysql_result($contactresult,"fax");
if ($pphone != ""){
$ph = "Ph: " . $pphone;
}
else if ($pmob != ""){
$ph = "Mob: " . $pmob;
}
else if ($pah != ""){
$ph = "A/H: " . $pah;
}
else if ($pfax != ""){
$ph = "Fax: " . $pfax;
}
As you can see, I am pulling all the contact numbers from the table, then chosing the first number the script comes accross as the number to use. The problem is that all of the contact numbers are optional, and for some reason when the script gets to a listing without a Phone number, it uses the phone number of the previous listing. That is bad.
I have even tried resetting all of those variables mentioned above by going...
$pphone = "";
$pmob = "";
$pah = "";
$pfax = "";
at the start, so each time it goes through the loop it has all the variables equalling ""
Ummm... if anyone understands my confusing explanation, any ideas?
Pulling stuff from a databese. I am inside a while loop set up like so...
while ($myrow = mysql_fetch_array($result)){
then inside it I am doing a few SQL things to get some contact details from a table...
$contactsql = "SELECT phone, mobile_phone, after_hours_phone, fax FROM people WHERE person_id = '$persid' AND person_name = 'Main'";
$contactresult = mysql_query($contactsql);
$pphone = mysql_result($contactresult,"phone");
$pmob = mysql_result($contactresult,"mobile_phone");
$pah = mysql_result($contactresult,"after_hours_phone");
$pfax = mysql_result($contactresult,"fax");
if ($pphone != ""){
$ph = "Ph: " . $pphone;
}
else if ($pmob != ""){
$ph = "Mob: " . $pmob;
}
else if ($pah != ""){
$ph = "A/H: " . $pah;
}
else if ($pfax != ""){
$ph = "Fax: " . $pfax;
}
As you can see, I am pulling all the contact numbers from the table, then chosing the first number the script comes accross as the number to use. The problem is that all of the contact numbers are optional, and for some reason when the script gets to a listing without a Phone number, it uses the phone number of the previous listing. That is bad.
I have even tried resetting all of those variables mentioned above by going...
$pphone = "";
$pmob = "";
$pah = "";
$pfax = "";
at the start, so each time it goes through the loop it has all the variables equalling ""
Ummm... if anyone understands my confusing explanation, any ideas?