OriginalSunny Posted March 8, 2006 Share Posted March 8, 2006 Hi,I am trying to get a picture as my link to another page in php. The thing is when the user will click on the picture a query should also be performed. I am currently using the following code for the user to select an option and the queryto be performed:[u]FIRST PAGE[/u][i] 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>"; } echo "<p><input type='submit' name='Products' value='Select Category'>\n [/i][u]SECOND PAGE[/u][i] $sql_cat = "SELECT DISTINCT class FROM food ORDER BY class"; $result = mysql_query($sql_cat,$connect) or die("sql_cat: ".mysql_error($connect)); while($row = mysql_fetch_array($result)) { $food_categories[$row['type']][]=$row['class']; } include("catalogContract.inc");[/i]As you can see a list of the class variables is displayed when the user clicks on the select category button. Now how do i use a picture instead?? I have stored the picture in my food database as foodpic.Thanks. Link to comment https://forums.phpfreaks.com/topic/4436-images-as-links/ Share on other sites More sharing options...
littlened Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=352860:date=Mar 8 2006, 02:32 PM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Mar 8 2006, 02:32 PM) [snapback]352860[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi,I am trying to get a picture as my link to another page in php. The thing is when the user will click on the picture a query should also be performed. I am currently using the following code for the user to select an option and the queryto be performed:[u]FIRST PAGE[/u][i] 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>"; } echo "<p><input type='submit' name='Products' value='Select Category'>\n [/i][u]SECOND PAGE[/u][i] $sql_cat = "SELECT DISTINCT class FROM food ORDER BY class"; $result = mysql_query($sql_cat,$connect) or die("sql_cat: ".mysql_error($connect)); while($row = mysql_fetch_array($result)) { $food_categories[$row['type']][]=$row['class']; } include("catalogContract.inc");[/i]As you can see a list of the class variables is displayed when the user clicks on the select category button. Now how do i use a picture instead?? I have stored the picture in my food database as foodpic.Thanks.[/quote]the simplest way to do it would be make the image a link, and use PHP do make the link dynamic.for exampleecho "<h3>$key</h3>"; echo "<ul>"; foreach($subarray as $type) { <a href="index.php?type=<?php echo $type; ?>"><img src="pic.gif" border="0"></a>"; }if you need the image to be different on each one, you could store the url of the image in a database or an array and do the same as what you do with the $type variable.eg<a href="index.php?type=<?php echo $type; ?>"><img src="<?php echo $picurl;?>" border="0"></a>"; Link to comment https://forums.phpfreaks.com/topic/4436-images-as-links/#findComment-15770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.