I've been searching on this topic for a couple days, but I'm not finding a solution, so maybe it's not possible?
Currently I have page that makes dozens of MySQL calls for name and email information.
<?php echo get_officer_listing("president"); ?>
these call the function get_officer_listing($position)
$sql = "SELECT OfficeTitle, OfficerName, OfficeEmail FROM officers WHERE officeshort = \"$position\"";
$officer = mysql_query($sql);
while($field = mysql_fetch_array($officer)) {
$title = $field["OfficeTitle"];
$name = $field["OfficerName"];
$email = $field["OfficeEmail"];
}
if (empty($name)) {$name = "Vacant";}
if (empty($email)) {$mailto = $name;}
else {$mailto = '<a href="mailto:'.$email.'">'.$name.'</a>';}
echo '<b>'.$title.'</b><br>'.$mailto.'<br>';
}
This works for returning a single officer listing with Office name and Officer name as a mailto link.
What I would like to do instead is call the officer table once and store all relevant records in a multivariable associative array indexed on the officerShortName. Then, at each officer listing, I could echo the array values like
<?php
$OfficeShortName = 'president';
echo $array[$OfficeShortName]['position'];
echo $array[$OfficeShortName]['OfficerName'];
echo $array[$OfficeShortName]['OfficeEmail'];
?>
So far I've been able to pull the records into an array and print all of them out in the While loop. But I haven't been able to call a single record's values after the loop.
Am I just not understanding how arrays work? Or is there a way to do this? Any help would be appreciated.