Jump to content

Images on database


turbocueca

Recommended Posts

Hello, I want to replace a value from a field in my mysql db by an image, but I don't know how to, I've tried using IF but it always gives error, maybe because I don't know where to it.

[code]         echo '<tr>
            <td width="250" scope="col"><b>'.$row[1].'<b></td>
            <td width="85" scope="col">'.$row[2].'</td>
            <td width="65"  scope="col">'.$row[3].'</td>
            <td width="250" scope="col">'.$row[4].'</td>
            <td width="100" scope="col">'.$row[5].'</td>
            <td width="150" scope="col">'.$row[6].'</td>            
            </tr>';
        }[/code]

This is the code that outputs the records form the db. I want to replace the values at the third row by an image thats located in my server. If you check [a href=\"http://infocenter.90megs.com\" target=\"_blank\"]http://infocenter.90megs.com[/a] you will see the images I mean, but in [a href=\"http://infocenter.90megs.com/index2.php\" target=\"_blank\"]http://infocenter.90megs.com/index2.php[/a] it doenst have any image, just 1,2,3, or 4 on the third row.

How can I replace those numbers by an image.
Can someone help me?

1 - images/wg.png
2 - images/po.png
3 - images/nwr.png
4 - images/dnas.png
Link to comment
https://forums.phpfreaks.com/topic/5344-images-on-database/
Share on other sites

If the image names are always the same, put the names of the files in an array:
[code]<?php $imgs = array('wg','po','nwr','dnas'); ?>[/code]
and then in the script that is to display them:
[code]<?php
         echo '<tr>
            <td width="250" scope="col"><b>'.$row[1].'<b></td>
            <td width="85" scope="col">'.$row[2].'</td>
            <td width="65"  scope="col">';
            list($width, $height, $type, $attr) = getimagesize('images/' . $imgs[$row[3]] . '.png');
            echo '<img src="images/' . $imgs[$row[3]] . '.png' . $attr . '></td>
            <td width="250" scope="col">'.$row[4].'</td>
            <td width="100" scope="col">'.$row[5].'</td>
            <td width="150" scope="col">'.$row[6].'</td>            
            </tr>';
        }
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19023
Share on other sites

take a look

[a href=\"http://infocenter.90megs.com/index3.php\" target=\"_blank\"]http://infocenter.90megs.com/index3.php[/a]


[code]   (...)
            $imgs = array('wg','po','nwr','dnas');
        
                while ($row=mysql_fetch_row($qq))
        {
        echo '<tr>
            <td width="250" scope="col"><b>'.$row[1].'<b></td>
            <td width="85" scope="col">'.$row[2].'</td>
            <td width="65"  scope="col">';
            list($width, $height, $type, $attr) = getimagesize('images/' . $imgs[$row[3]] . '.png');
            echo '<img src="images/' . $imgs[$row[3]] . '.png' . $attr . '></td>
            <td width="250" scope="col">'.$row[4].'</td>
            <td width="100" scope="col">'.$row[5].'</td>
            <td width="150" scope="col">'.$row[6].'</td>            
            </tr>';
        }
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19123
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.