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); Code: Select all
$showsystem = str_replace($SysName, $SysRename, $system); Code: Select all
echo ("
<div class='sub15'>$showsystem</div>
" );
}How can i automate this instead of writing each of them separately?
Thanks for any help..