I don't quite agree with you there matthiasone
your function query_db seems redundant. You are connecting over and over and over each time you execute a query. (also, your "mysql_close($connection);" statement is put after the return statement and so it is never executed at all)
I'd just put this at the top of each script that uses the database :
Code: Select all
/*** Connect to DataBase ***/
mysql_connect( "localhost" , "user" , "pass" )
OR die( "Could not connect : ".mysql_error());
mysql_select_db( 'dbname' )
OR die( "Error : ".mysql_errno()." : ".mysql_error()."<br>\n");
and then to execute a query I'd use this which is the same amount of code as you use for a query but minus the use of the function:
Code: Select all
$query = "Select * FROM blah";
$result = mysql_query($query)
OR exit_script("Error:".mysql_errno()." : ".mysql_error()."<br>\n");
while ($row = mysql_fetch_array($result))
// do stuff
__________________________________________________________
And susi, the answer to your question :
Code: Select all
$query = "SELECT player1 from members2 where username = [$SESSION_UNAME]";
$result = mysql_query($query) // THIS EXECUTES IT
OR exit_script("Error:".mysql_errno()." : ".mysql_error()."<br>\n");
while ($row = mysql_fetch_array($result)) { // THIS GETS EACH ROW AT A TIME FROM THE RESULT
// do stuff with each row eg
print $row['player1']."<BR>";
}
Oh and one more thing ... try and spend a couple of seconds thinking of a more suitable title for your message. Something that explains the question briefly. Instead of "URGENT HELP!!" you could use something like "How to get the results of a query". Some people may have the same problem and if they saw a title that explained their problem they are more likely to see your response thant post another redundant message.
Cheers