why wont this var echo??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

why wont this var echo??

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

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

$row = mysql_fetch_assoc($result);

print_r($row);
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

well

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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"]; 

?>
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

hmm

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;'
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

no

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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"];
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

thank you thank you

Post by fresh »

it works , thanks alot ;)
Post Reply