Jump to content

Arrays, Variables and Database queries


kreut

Recommended Posts

Hello,

 

I've created a function whereby I want to return the school_id associated with a particular user.  Each user will be associated with exactly one school.  My query below works, but the thing that it returns is an array; I need to make use of it as a variable (say $instructor_school_id).  Any idea how to make the conversion from a single element array into a non-array variable?

 

Thank you....

 

function getInstructorSchool($read, $user_id) {
$sql = "SELECT school_id
		FROM users
		WHERE user_id = $user_id";
return $read->fetchRow($sql);
}

 

Link to comment
https://forums.phpfreaks.com/topic/227668-arrays-variables-and-database-queries/
Share on other sites

Echo out the contents of the variable that is returned from your function.

<?php
$variable = getInstructorSchool($read, $user_id);
echo '<pre>';
print_r($variable);
echo '</pre>';
?>

Do something like that, paste your output here, and I will tell you how to get it into a variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.