...

View Full Version : Why doesn't this work? (mysql stuff)



hlinzi
04-14-2012, 08:43 PM
the part that doesn't work is
$user = mysql_query("SELECT * FROM players WHERE name='$phpuser'"); I THINK, because i cant
echo $user['zone'] or anything..

Please help :)
btw yes there are actual users in the table and stuff :D


...
$phpuser = $_SERVER['PHP_AUTH_USER'];
$user = mysql_query("SELECT * FROM players WHERE name='$phpuser'");
?>

<html>
<body>
<?php
$userzone = $user['zone'];
echo 'php user: ' . $phpuser;
$q = mysql_query("SELECT * FROM players WHERE zone='$userzone'");
while($i = mysql_fetch_array($q))
{
echo $i['name'] . " is in " . $i['zone'];
}
?>
</body>
</html>

If you're wondering what I'm doing then it's selecting a user based on htaccess authentication and then finding everyone in his zone..

litebearer
04-14-2012, 09:59 PM
this returns a RESOURCE


$user = mysql_query("SELECT * FROM players WHERE name='$phpuser'");


to get the record you need (if there is only one record)


$row = mysql_fetch_array($user);
echo $row['zone'];

for multiple records use a while loop



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum