Creating a Status Indicator (like ICQ)

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
EverToDesign
Forum Newbie
Posts: 10
Joined: Sat Oct 11, 2003 9:38 am

Creating a Status Indicator (like ICQ)

Post by EverToDesign »

Hey, heres the problem.

from a control panel a member can change their status Available/Not available/busy which is put into a MySQL Table with their record.

Now i need it so an .html page can parse this information and return an appropriate icon like ICQ Status Indicators

Ex- if a person was offline an image should appear that would represent them being offline, if online one for online if busy one for busy.

How do I go about doing this? I looked at ICQ's code but its just an IMG SRC Tag to a script not an actual image.

Any ideas or pointers to tutorials for this?

Thanks in advance
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Code: Select all

<?php
/* the variable "status" should be set to whatever the users current status is */
switch ($status)
{
case 'away' :
$icon = "AWAYICON.jpg";
break;

case 'busy' :
$icon = "BUSYICON.jpg";
break;

default :
$icon = "DEFAULTICON.jpg";
break;
}

echo "<img src="$icon">";

?>
EverToDesign
Forum Newbie
Posts: 10
Joined: Sat Oct 11, 2003 9:38 am

Post by EverToDesign »

Thanks for the quick code snippet but just where would I implement that? I need to have the status show up on a .html page in an img src tag preferbly.

Would I be bale to link it to a page ex <img src="http://www.sitehere.com/status.php">

and then have the switch code there where it simply echos out the img src tag you showed, would that make the image appear?
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

Yes you can link it to a php page by using <img src="generateIconStatus.php" /> However. You will have to pass varialbes to the "image" so you would then call it by <img src="generateIconStatus.php?status=away" />.

In the php file (generateIconStatus.php in this example) You will need to use the header() function to send a Content Type for the image you will be displaying (ie, header('Content-Type: image/jpeg');).. So it could be something that incorporates what nigma said, but with the addition of the header() call.

eg,
nigma wrote:

Code: Select all

<?php
/* the variable "status" should be set to whatever the users current status is */
switch ($status)
{
case 'away' :
$icon = "AWAYICON.jpg";
break;

case 'busy' :
$icon = "BUSYICON.jpg";
break;

default :
$icon = "DEFAULTICON.jpg";
break;
}
 /* See below */
?>

Code: Select all

header('Content-Type: image/jpeg');
echo '<img src="' . $icon . '">';
?>
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

You could implement that wherever you would want the image to be.

Example:

Code: Select all

<div id="status">
<?php
/* the variable "status" should be set to whatever the users current status is */ 
switch ($status) 
&#123; 
case 'away' : 
$icon = "AWAYICON.jpg"; 
break; 

case 'busy' : 
$icon = "BUSYICON.jpg"; 
break; 

default : 
$icon = "DEFAULTICON.jpg"; 
break; 
&#125; 
?>
</div>
Post Reply