Page 1 of 1

why wont this var echo??

Posted: Thu Jul 15, 2004 12:46 am
by fresh
hey,

trying to query the db and echo the val, of the row, but it's echoing the var instead...

Code: Select all

$ranks = "SELECT `rank` FROM `users` WHERE `username` = '{$name}'";
 @mysql_query($ranks) or die(mysql_error());

echo "blah".$ranks."blah";
how could I echo just that specific row??? thanks

Posted: Thu Jul 15, 2004 12:57 am
by feyd

Code: Select all

$result = @mysql_query($ranks) or die(mysql_error());

$row = mysql_fetch_assoc($result);

print_r($row);

well

Posted: Thu Jul 15, 2004 1:30 am
by fresh
it's not working:

Code: Select all

$ranks = "SELECT `rank` FROM `users` WHERE `username` = '{$name}'";
$result = @mysql_query($ranks) or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo ".$row.";
just echos the Array[=blah] > thing... I was wanting to echo the value of that row, for that user only... thanks

Posted: Thu Jul 15, 2004 1:46 am
by John Cartwright

Code: Select all

<?php

$ranks = "SELECT `rank` FROM `users` WHERE `username` = '{$name}'"; 
$result = @mysql_query($ranks) or die(mysql_error()); 
$row = mysql_fetch_assoc($result); 
echo $row["user"]; 

?>

hmm

Posted: Thu Jul 15, 2004 2:06 am
by fresh
no, still not working, now it isn't echoing anything... what was the user thing for, was that for me to put the users name I want to get into??? I am doing this dynamically so I dont need to make a page for every one, im trying to get the value of three columns; rank, points, and login_date, and then echo them on the page... can anyone show me how to do this please, thanks


example page:

Nick : $name -- users name according to $name var which is a session var
Rank : $ranks -- what rank they have according to what user it is
Points : $pts -- how many points they have according what user it is

so, again, Im just trying to grab these values, according to who it is who wants to know... thanks :)

Posted: Thu Jul 15, 2004 2:40 am
by feyd
you are selecting just `rank` from the table `users`, do you want the other fields? If so

Code: Select all

SELECT * FROM `users` WHERE `username` = '&#123;$uname&#125;'

no

Posted: Thu Jul 15, 2004 3:10 am
by fresh
I want just one field at a time:

pretend this: $rank, is a var representing a sql select string in the rank column... this is placed on my php page like so:

Rank: $rank

the user views this page, his session var is checked and according to that, his info, will be takin from the db, for example rank, and points, and last login...

just one person (which depends on their session username), and their rank and points and last_login rows only... thanks

Posted: Thu Jul 15, 2004 3:20 am
by feyd
my above will basically find 1 user and pull all their data. You still choose what and whether to show things after that select still..

Posted: Thu Jul 15, 2004 3:22 am
by Wayne
Phenom .... sorry but you made a smal mistake
<?php

$ranks = "SELECT `rank` FROM `users` WHERE `username` = '{$name}'";
$result = @mysql_query($ranks) or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo $row["user"];

?>
you can only display the col. values you selected .... so change

Code: Select all

echo $row["user"];
to

Code: Select all

echo $row["rank"];

thank you thank you

Posted: Thu Jul 15, 2004 4:10 am
by fresh
it works , thanks alot ;)