turbocueca Posted March 20, 2006 Share Posted March 20, 2006 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.png2 - images/po.png3 - images/nwr.png4 - images/dnas.png Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/ Share on other sites More sharing options...
kenrbnsn Posted March 20, 2006 Share Posted March 20, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19023 Share on other sites More sharing options...
turbocueca Posted March 20, 2006 Author Share Posted March 20, 2006 will it detect the value of the fieldfor each record ? (1,2,3,4) Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19057 Share on other sites More sharing options...
kenrbnsn Posted March 20, 2006 Share Posted March 20, 2006 Try it, if it doesn't work (and I really think it will work fine), then post the problems.Ken Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19092 Share on other sites More sharing options...
turbocueca Posted March 20, 2006 Author Share Posted March 20, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19123 Share on other sites More sharing options...
ober Posted March 20, 2006 Share Posted March 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19130 Share on other sites More sharing options...
turbocueca Posted March 20, 2006 Author Share Posted March 20, 2006 Works fine.Thanks Ken, Thanks Ober. Quote Link to comment https://forums.phpfreaks.com/topic/5344-images-on-database/#findComment-19146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.