kreut Posted February 14, 2011 Share Posted February 14, 2011 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); } Quote Link to comment https://forums.phpfreaks.com/topic/227668-arrays-variables-and-database-queries/ Share on other sites More sharing options...
cyberRobot Posted February 15, 2011 Share Posted February 15, 2011 I don't know what $read->fetchRow($sql); does, but you should be able to get a non-array variable by doing something like: <?php ... $school_id = myArray[0]; ?> or maybe: <?php ... $school_id = myArray['school_id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/227668-arrays-variables-and-database-queries/#findComment-1174351 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227668-arrays-variables-and-database-queries/#findComment-1174404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.