Jump to content

Pair Array Results to Replace Images


erturanya

Recommended Posts

hi, i am trying to visualize a table by replacing the fixed values with images.

For example, i have a visitor statistics table on mysql. Values on the config_os table are always in three letters. WI7 for Windows7, MAC for Macintosh. I hope I can tell this correctly.

I have a display page which retrieves the values from database and displays them website statistics.

But in order to make it more cool, i am telling to PHP that When you echo to divtable WI7, replace them with specified Windows7 icon image which has identical name as WI7.gif. Here is the code:

 

        include("conn.php");
    	$sql="SELECT *, INET_NTOA(location_ip) AS location_ip FROM xx_log_visit AS location_ip ORDER BY idvisit DESC LIMIT 10";
// I am selecting all so you can't see config_os but it is there . I cropped unnecessary code for keeping it easy to read.

    	$result=mysql_query($sql);
        $numofrows = @mysql_num_rows($result);
    
    	
    	while($row = mysql_fetch_array($result))
    	{

$system = $row['config_os'];
                $SysName = array ("AND", "IPH", "LIN", "MAC", "UNK", "W2K", "W95", "W98", "WI7", "WME", "WNT", "WOS", "WS3", "WVI", "WXP");
                $SysRename = array ("<img src='images/os/AND.gif'>","<img src='images/os/IPH.gif'>","<img src='images/os/LIN.gif'>","<img src='images/os/MAC.gif'>","<img src='images/os/UNK.gif'>","<img src='images/os/W2K.gif'>","<img src='images/os/W95.gif'>","<img src='images/os/W98.gif'>","<img src='images/os/wi7.gif'>","<img src='images/os/WME.gif'>","<img src='images/os/WNT.gif'>","<img src='images/os/WOS.gif'>","<img src='images/os/WS3.gif'>","<img src='images/os/WVI.gif'>","<img src='images/os/WXP.gif'>");
                $showsystem= str_replace($SysName, $SysRename, $system);

 

What I do here is simply use strreplace function.

 

$showsystem = str_replace($SysName, $SysRename, $system);

 

and in the display table, continue from code:

 

            echo ("
                <div class='sub15'>$showsystem</div>
            " );        
}

 

So for example instead of writing WI7 as visitors os, it shows WI7.gif, cool hmm :)

 

How can i automate this instead of writing each of them separately?

 

Thanks for any help..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.