Jump to content

Recommended Posts

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

[!--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 example


echo "<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

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.