Hi all!
So i'm coding away on a project and I have been writing some functions on my pages and I'm running into something strange and I can't figure it out.
If I write a SQL Statement at the top of the header with a MYSQL_FETCH_ASSOC($result) to fetch the results of a query and then try adding in those results inside a function they won't show up. Here is an example:
require_once('connect.php');
$query = "SELECT * FROM TABLE";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
function something()
{
if ($row['status'] == "True")
{
echo $row['name'];
}
else
{
echo "something else";
}
}
// run function
something();
If the statement is "True" it should output $row['name'] or something. But I'm getting no results.
The way I can get it to work is to write it like this:
function something()
require_once('connect.php');
$query = "SELECT * FROM TABLE";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
{
if ($row['status'] == "True")
{
echo $row['name'];
}
else
{
echo "something else";
}
}
// run function
something();
But this is a pain because I don't want to have to write in so many sql queries. any ideas. This is the best way that I can explain my problem, sorry if i don't make sense.