Jump to content


Photo

using pictures as links


  • Please log in to reply
1 reply to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 03 March 2006 - 12:16 PM

Hi,

i am working on designing a webpage. I give a list of options for the user to choose from and then once the user has choosen what they want the products avaliable on the option are displayed. The code i have used is:

foreach($food_categories as $key => $subarray)
{
echo "<h3>$key</h3>";
echo "<ul>";
foreach($subarray as $type)
{
echo "<input type='radio' name='interest'
value='$type'><b>$type</b><br>\n";
}
echo "</ul>";
}

This works however u want the user to be able to select from a set of pictures. I have stored the pictures in the database under the heading "pic". A helpful person posted the following code for me to do this however the code doesnt seem to work:

foreach($food_categories as $key => $subarray)
{
echo "<img src=\"$food_categories[$key]['pic']\">";
}

Can any one tell me whats wrong with it please??? Thanks


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 March 2006 - 01:23 PM

you will have to place the image generation script into a separate file...

e.g.

genimage.php

<?php
$qry = mysql_query("SELECT `pic` FROM `yourtable` WHERE `uniqueid` = '$picid'");
echo mysql_result($qry,0,"pic");
?>

Then in your imgtag put this...

<img src="genimage.php?picid=<?php echo $food_categories[$key][UNIQUEID];?>">

making sure you replace the UNIQUEID with the name of the field in your table that is the primary (or what ever else you use to identify it)
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users