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
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 12:11 am
cool, was wondering simular things, I want to change my users picks as there points go up and ranks change so would I do that like this:
Code: Select all
$sql = "SELECT `points` FROM `users`";
if($sql >= 1000) {
$img = "<img src='blah'>";
} else {
if($sql >= 4000) {
$img = "<img src='blah2'>";
} else {
if($sql >= 10000) {
$img = "<img src='blah3'>";
} else {
die("houston, we have a problem!");
}
I fixed the code and now it works... thanks
Last edited by
fresh on Sun Jul 18, 2004 2:43 am, edited 2 times in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 12:18 am
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 12:21 am
see I knew I posted something..lol any advice other than what I have already gotten??? thanks guys
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 12:23 am
Code: Select all
<?php
$query = "SELECT `points` FROM `users` WHERE `id` = '$id'";
$res = mysql_query($query) or die(mysql_error());
$sql = mysql_result($res,0,0);
if($sql >= 10000) {
$img = "<img src='blah3'>";
} elseif($sql >= 4000) {
$img = "<img src='blah2'>";
} elseif($sql >= 1000) {
$img = "<img src='blah3'>";
} else {
die("houston, we have a problem!");
}
?>
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 12:26 am
thanks feyd!! How come you put them upside down, does it parse better that way??? Also, does the apostraphes have to be there??? How come they are??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 12:54 am
fresh wrote: thanks feyd!! How come you put them upside down, does it parse better that way??? Also, does the apostraphes have to be there??? How come they are??
they are upside down because otherwise, 15000 would still get 1000's image.
As for the apostraphes, in:
Code: Select all
"SELECT `points` FROM `users` WHERE `id` = '$id'"; the bulk of those are actually backticks or backquotes. They are used to make sure sql considers them names versus keywords.. it's a precaution most of the time.
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 2:56 am
how come 15000 would get 1000's pic, otherwise?? The logical thing would be to start at 0 and move up, right???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 3:03 am
looking at your orignal thoughts.. lets say $sql = 15000.
$sql >= 1000 is true.
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 3:12 am
I thought this ---| > equaled greater than, therfore, >= equals, greater than or equal to... so, that would mean if $sql = 15000, then 1000 would return 0...
right?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 3:14 am
it translates to:
is variable "sql" greater than or equal to 1000
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 3:16 am
ok. otherwise my logic would be correct???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 3:21 am
what other logic?
that 15000 is greather than or equal to 1000's answer is no?
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 3:57 am
I forgot 1000 is more than 15000... my bad
jk
fresh
Forum Contributor
Posts: 259 Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika
Post
by fresh » Fri Jul 16, 2004 6:01 am
this code isn't working:
Code: Select all
<?php
$name = $_SESSION['usernam'];
$query = "SELECT `points` FROM `users` WHERE `username` = '$name'";
$res = mysql_query($query) or die(mysql_error());
$sql = mysql_result($res,0,0);
if($sql >= 10000) {
$img = "<img src='blah3'>";
} elseif($sql >= 4000) {
$img = "<img src='blah2'>";
} elseif($sql >= 1000) {
$img = "<img src='blah3'>";
} else {
die("houston, we have a problem!");
}
?>
it says cannot jump to row 0 or something like that, I entered 1 and it said it couldnt jump to row 1... any help thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 6:03 am
sounds like it didn't return any rows..