Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resource id #3

Status
Not open for further replies.

janet24

Technical User
Jul 22, 2003
161
US
I'm missing something in this code to make it work. Right now the output is Resource id #3

My database has a username which is janet and a scorer which is 4. I want the results of the scorer where the user name is janet to be displayed. This should be easy for somebody but not me.

<?

$conn = mysql_connect("localhost","xxx","xxx") or die(mysql_error());
mysql_select_db('score',$conn) or die(mysql_error());


$q = "select scorer from scoreuser where username='janet' ";
$res = mysql_query($q,$conn);


if ($res)
{
echo "".$res;
}
else
{echo "Thank you";
}

mysql_close($conn);
?>
 
I got this to work but I can't image this is the best way to write this code or isn't it?


<?

$conn = mysql_connect("localhost","xxx","xxx") or die(mysql_error());
mysql_select_db('score',$conn) or die(mysql_error());


$q = "select scorer from scoreuser where username='janet' ";
$res = mysql_query($q,$conn);
$row=mysql_fetch_array($res);
$result=$row['scorer'];

if ($result==4){
echo "It works and outputs number " .$result;
}
mysql_close($conn);
?>
 
I guess I don't understand why you would need an array if your only looking for one result. I'm just so new at it I thought maybe I was in left field somewhere.

That's where I got the results is from the PHP online manual.

Thanks...
 
It's simply because the functions return arrays. Sometimes, yes, arrays of single elements, in the cases that the resultset only has one column.


Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top