Pair Array Results to Replace Images

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
erturanya
Forum Newbie
Posts: 1
Joined: Sun Dec 05, 2010 11:23 am

Pair Array Results to Replace Images

Post by erturanya »

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:

Code: Select all

        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.

Code: Select all

$showsystem = str_replace($SysName, $SysRename, $system); 
and in the display table, continue from code:

Code: Select all

            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..
Post Reply