PDA

View Full Version : another Functions issue for me


2bz2p
07-28-2008, 09:55 PM
Hi,

So I think I got this right though the function is not oputting the array.

include ('settings.inc.php') ;
$callsign = 'bat100';
function pilot_query() {

global $database_conn_abrv, $conn_abrv, $callsign;

//////////////////////////////////// PILOT INFORMATION QUERY ///////////////////////////////
/*Lets Query the DB for all of the logged in Pilots info*/
mysql_select_db($database_conn_abrv, $conn_abrv);
$query_pilot = "SELECT * FROM pilot WHERE callsign = '$callsign'";
$pilot = mysql_query($query_pilot, $conn_abrv) or die(mysql_error());
$row_pilot = mysql_fetch_assoc($pilot);
$all_rows_pilot = mysql_num_rows($pilot);
///////////////////////////////////// END PILOT QUERY ////////////////////////////////////////


/* Lets put everything in the database into an array */
$pilot = array(
'id' => $row_pilot['id'],
'pilot_id' => $row_pilot['pilot_id'],
'callsign' => $row_pilot['callsign'],
'user_name' => $row_pilot['user_name'],
'name' => $row_pilot['name'],
'email' => $row_pilot['email'],
'skin' => $row_pilot['skin'],
'vatsim_id' => $row_pilot['vatsim_id'],
'hub' => $row_pilot['hub'],
'dob' => $row_pilot['dob'],
'location' => $row_pilot['location'],
'password' => $row_pilot['password'],
'background' => $row_pilot['background'],
'join_date' => $row_pilot['join_date'],
'status' => $row_pilot['status'],
'activated' => $row_pilot['activated'],
'site_level' => $row_pilot['site_level'],
'staff' => $row_pilot['staff'],
'flight_serial' => $row_pilot['name'],
);
return $pilot;
}

pilot_query();

echo $pilot['name'];
?>

So my question is whats wrong.

Thanks
2b

2bz2p
07-28-2008, 10:10 PM
I got it I am a dope, gotta add the $pilot to the global list to have it output outside of the function.

though if there is another way to do this please let me know

thanks
2b

davidj
07-28-2008, 11:03 PM
try this below your function


$pilot = pilot_query();

echo $pilot['name'];

2bz2p
07-29-2008, 01:00 AM
That worked nicely, but why did it have to be called into the variable $pilot in order for the array to work

thanks again 2b

davidj
07-29-2008, 08:00 AM
if your function returns a value then you need somewhere to put the value in so this is why i used a variable

2bz2p
07-29-2008, 02:23 PM
Got ya

Thanks again
2b