How can I use return the $row
array in the below example, so that I can re-use the variable outside of this function?
I manage to echo the information inside the function using $row['columnName']
, but various combinations of global
and $GLOBALS
, return $xyz
and getting variable scope to work for me has me a bit out of my depth. Any answers please?
<?php
function getInfo() {
$query = /* Some SQL Query */;
$result = mysql_query($query);
if($result == false)
{
user_error("Query failed: " . mysql_error() . "<br />
$query");
}
elseif(mysql_num_rows($result) == 0)
{
echo "<p>Sorry, no rows were returned by your query.</p>
";
}
else
{
while ($row = mysql_fetch_assoc($result)) {
/* What goes here? */
}
}
}
?>