Mink_
02-16-2005, 01:08 AM
I'm working on a web-RPG, and need a little help with my database queries, as I need to be setting up globals using unfctions.
I'm using this simple code that I came up with after a few minutes of looking at the PHP manual (I've already set the database up):
function getuserinfo($id) {
$query = mysql_query("SELECT * FROM users WHERE id = $id LIMIT 1");
$user = mysql_fetch_array($query);
}
Then, I want to call values from that by using things like $user['var'].
The only problem is, I can only seem to call values from that array inside the function, meaning that this will work:
function getuserinfo($id) {
$query = mysql_query("SELECT * FROM users WHERE id = $id LIMIT 1");
$user = mysql_fetch_array($query);
echo $user['var'];
}
getuserinfo(1);
And this will not:
function getuserinfo($id) {
$query = mysql_query("SELECT * FROM users WHERE id = $id LIMIT 1");
$user = mysql_fetch_array($query);
}
getuserinfo(1);
echo $user['var'];
Is there an alternate way of getting the results I would see if the second bit of code worked? Or do I have to redesign my entire system? :rolleyes:
I'm using this simple code that I came up with after a few minutes of looking at the PHP manual (I've already set the database up):
function getuserinfo($id) {
$query = mysql_query("SELECT * FROM users WHERE id = $id LIMIT 1");
$user = mysql_fetch_array($query);
}
Then, I want to call values from that by using things like $user['var'].
The only problem is, I can only seem to call values from that array inside the function, meaning that this will work:
function getuserinfo($id) {
$query = mysql_query("SELECT * FROM users WHERE id = $id LIMIT 1");
$user = mysql_fetch_array($query);
echo $user['var'];
}
getuserinfo(1);
And this will not:
function getuserinfo($id) {
$query = mysql_query("SELECT * FROM users WHERE id = $id LIMIT 1");
$user = mysql_fetch_array($query);
}
getuserinfo(1);
echo $user['var'];
Is there an alternate way of getting the results I would see if the second bit of code worked? Or do I have to redesign my entire system? :rolleyes: