Echo image

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
ewannnn
Forum Newbie
Posts: 13
Joined: Thu Nov 04, 2010 9:46 am

Echo image

Post by ewannnn »

Hi, I need some help with some PHP code please.
I have a database with a table 'users' with an attribute 'status', set to default '0', and when a user logs in this changes to '1'.
I have then echoed the results of this table with something like so:

Code: Select all

$query=mysql_query("SELECT * FROM userTable;");	
	echo "<table>";
		//while loop for rows					       
           	while($rows=mysql_fetch_array($query)){
                echo "<tr>";			
                    echo "<td>" . $rows['username'] . "</td>" . "<td>" . $rows['status'] . "</td>";   
                echo "</tr>";							
         	}
...what I want to do is, if a user is online, echo a <td> with an image in it (rather than $rows['status']), say a green square, and a red square if they are offline.
To echo the image it's obviously (something like):

Code: Select all

echo '<img src="someLocation/thisImage.jpg">';
...what I am asking is how do i defferentiate between the '1' for online and the '0' for offline in the code?

Thanks in advance for any replies...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Echo image

Post by requinix »

Look at that code, make a couple educated guesses, then learn to use the if control structure.
ewannnn
Forum Newbie
Posts: 13
Joined: Thu Nov 04, 2010 9:46 am

Re: Echo image

Post by ewannnn »

Thanks, sorry I should have made it clearer - I tried that first...in the while loop a bit like this:

Code: Select all

while($rows=mysql_fetch_array($query)){
                if($rows['status']='1'){
                    echo "<tr>";                    
                        echo "<td>" . $rows['username'] . "</td>" . "<td>" . <img src GREEN> . "</td>";   
                    echo "</tr>";  
                } else {  
                    echo "<tr>";                    
                        echo "<td>" . $rows['username'] . "</td>" . "<td>" . <img src RED> . "</td>";   
                    echo "</tr>";  
                                    
Obviously the red/green image src is not the exact syntax, but you get the idea.

Any other suggestions I would be greatful, thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Echo image

Post by requinix »

Code: Select all

if($rows['status']='1'){
One = means assignment, two ==s means comparison.
ewannnn
Forum Newbie
Posts: 13
Joined: Thu Nov 04, 2010 9:46 am

Re: Echo image

Post by ewannnn »

Thanks I have actually tried both, none work...
Post Reply