Jump to content


Photo

Images on database


  • Please log in to reply
6 replies to this topic

#1 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 20 March 2006 - 02:11 PM

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.

        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>';
        }

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


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 March 2006 - 02:43 PM

If the image names are always the same, put the names of the files in an array:
<?php $imgs = array('wg','po','nwr','dnas'); ?>
and then in the script that is to display them:
<?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>';
        }
?>

Ken


#3 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 20 March 2006 - 05:18 PM

will it detect the value of the fieldfor each record ? (1,2,3,4)

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 March 2006 - 06:52 PM

Try it, if it doesn't work (and I really think it will work fine), then post the problems.

Ken

#5 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 20 March 2006 - 08:00 PM

take a look

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


   (...)
            $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>';
        }
?>


#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 20 March 2006 - 08:28 PM

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.

Info: PHP Manual


#7 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 20 March 2006 - 09:10 PM

Works fine.

Thanks Ken, Thanks Ober.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users