Page 1 of 2

[SOLVED] Changing user pictures

Posted: Fri Jul 16, 2004 12:11 am
by fresh
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 :)

Posted: Fri Jul 16, 2004 12:18 am
by feyd

oh

Posted: Fri Jul 16, 2004 12:21 am
by fresh
see I knew I posted something..lol any advice other than what I have already gotten??? thanks guys :)

Posted: Fri Jul 16, 2004 12:23 am
by feyd

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!"); 
}

?>

great

Posted: Fri Jul 16, 2004 12:26 am
by fresh
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??

Re: great

Posted: Fri Jul 16, 2004 12:54 am
by feyd
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.

hmm

Posted: Fri Jul 16, 2004 2:56 am
by fresh
how come 15000 would get 1000's pic, otherwise?? The logical thing would be to start at 0 and move up, right???

Posted: Fri Jul 16, 2004 3:03 am
by feyd
looking at your orignal thoughts.. lets say $sql = 15000.
$sql >= 1000 is true.

hmm

Posted: Fri Jul 16, 2004 3:12 am
by fresh
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?

Posted: Fri Jul 16, 2004 3:14 am
by feyd
it translates to:

is variable "sql" greater than or equal to 1000

oh

Posted: Fri Jul 16, 2004 3:16 am
by fresh
ok. otherwise my logic would be correct??? :oops:

Posted: Fri Jul 16, 2004 3:21 am
by feyd
what other logic?

that 15000 is greather than or equal to 1000's answer is no?

oh

Posted: Fri Jul 16, 2004 3:57 am
by fresh
I forgot 1000 is more than 15000... my bad ;) jk :)

anyway....

Posted: Fri Jul 16, 2004 6:01 am
by fresh
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 :)

Posted: Fri Jul 16, 2004 6:03 am
by feyd
sounds like it didn't return any rows..