Okay... I am trying to get some contact numbers from a database, and choose the first available number in order of preferance (that is what all those case statements are...) Here is the entire code. With any luck you guys might be able to figure out what I am doing here 🙂
<?php
$sql = "SELECT * FROM entities ORDER BY entity_name ASC";
$result = mysql_query($sql);
while ($myrow = mysql_fetch_array($result)){
$entidtoget = $myrow["entity_id"];
$getstuffsql = "SELECT entity_department_id FROM entity_departments WHERE entity_id = '$entidtoget' and entity_department_name = 'Main'";
$phnumbs = mysql_query($getstuffsql);
$entdepid = mysql_result($phnumbs,"entity_department_id");
$getstuffsql = "SELECT person_id FROM entity_department_members WHERE entity_department_id = '$entdepid'";
$phnumbs = mysql_query($getstuffsql);
$persid = mysql_result($phnumbs,"person_id");
$namesql = "SELECT phone, mobile_phone, after_hours_phone, fax FROM people WHERE person_id = '$persid' AND person_name = 'Main'";
$pphone = "";
$pmob = "";
$pah = "";
$pfax = "";
$nameresult = mysql_query($namesql);
$pphone = mysql_result($nameresult,"phone");
$pmob = mysql_result($nameresult,"mobile_phone");
$pah = mysql_result($nameresult,"after_hours_phone");
$pfax = mysql_result($nameresult,"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;
}
printf("<tr>\n <td><a href=\"#\">%s</a></td>\n <td>%s</td>\n </tr>", $myrow["entity_name"], $ph);
}
?>
Good luck trying to understand that!
But anyway, here's my problem:
When the script gets a record that has no phone number, for some reason it inherits the number from the previous record instead of looking for the next preferance....
Thanks in advance!