I've done a query to collect some information from my DB in a .php document, and returned a value via return $var;
I now want to use this value in another .php document in the same root dir. I've tried to simply state the variable in the other code document, but then I get an error message saying that my variable is undefined.
The function works similar to this one: http://se2.php.net/manual/en/function.mysql-fetch-assoc.php
And this code is present at text.func.php, I now want to use the return array in search.php
What should I do to get my value from the return, to the other page, where I want to execute more code with it?
I appreciate any kind of help. Thank you in advance.
Code:
In text.func.php:
function search($query) {
$query = mysql_real_escape_string($query);
$sql = "SELECT * FROM `text` WHERE categories LIKE '%$query%'";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
echo $rows[] = $row;
}
mysql_free_result($result);
return $rows;
$rows is the variable that I want to do a foreach with and echo out on another page.