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