Problem with either a query or IF Statement

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
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Problem with either a query or IF Statement

Post by Cooperman »

Can someone show me how I would write the IF Statement for:

I want the script to be able to go to the DB and see what access level is set.
1 should go to guest
2 should go to members

I'm not sure if it's my query at fault or the IF statement but every time it seems to be going to guest even if I have a "2" in my access row on the DB.

Please help. :cry:


$sql = 'SELECT * FROM `login`';
$result = mysql_query($sql);


if ($result ['access'] > 1) {
echo ("members only");

} else {

echo ("guest only");
}
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Problem with either a query or IF Statement

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Problem with either a query or IF Statement

Post by Cooperman »

Thanks,

So how would I write that in the code? Sorry, I am a real Newbie to this...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Problem with either a query or IF Statement

Post by VladSun »

There is a very good example in the manual I've pointed to. ;)
There are 10 types of people in this world, those who understand binary and those who don't
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Problem with either a query or IF Statement

Post by Cooperman »

Is this also the right way to query the DB for the row ACCESS?

if ($result ['access'] > 1) {
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Problem with either a query or IF Statement

Post by VladSun »

Please, read-the-manual ... All of your questions have their answers there.
There are 10 types of people in this world, those who understand binary and those who don't
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Problem with either a query or IF Statement

Post by Cooperman »

Thanks :)
Post Reply