Jump to content

Archived

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

turbocueca

Images on database

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Try it, if it doesn't work (and I really think it will work fine), then post the problems.

Ken

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
A quick look at your source reveals that you're not closing the quotation marks after the image path:

echo '<img src="images/' . $imgs[$row[3]] . '.png" ' . $attr . '></td>

That should work.

Share this post


Link to post
Share on other sites

×

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.