[SOLVED] Changing user pictures

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

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

[SOLVED] Changing user pictures

Post 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 :)
Last edited by fresh on Sun Jul 18, 2004 2:43 am, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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

oh

Post by fresh »

see I knew I posted something..lol any advice other than what I have already gotten??? thanks guys :)
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

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

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

great

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

Re: great

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

hmm

Post by fresh »

how come 15000 would get 1000's pic, otherwise?? The logical thing would be to start at 0 and move up, right???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

looking at your orignal thoughts.. lets say $sql = 15000.
$sql >= 1000 is true.
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

hmm

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

Post by feyd »

it translates to:

is variable "sql" greater than or equal to 1000
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

oh

Post by fresh »

ok. otherwise my logic would be correct??? :oops:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what other logic?

that 15000 is greather than or equal to 1000's answer is no?
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

oh

Post by fresh »

I forgot 1000 is more than 15000... my bad ;) jk :)
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

anyway....

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

Post by feyd »

sounds like it didn't return any rows..
Post Reply