Jump to content

Archived

This topic is now archived and is closed to further replies.

OriginalSunny

Images as links

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.

Share this post


Link to post
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>";


Share this post


Link to post
Share on other sites

×

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.