Jump to content


Photo

Images as links


  • Please log in to reply
1 reply to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 08 March 2006 - 02:32 PM

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:

FIRST PAGE
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


SECOND PAGE
$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");


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.

#2 littlened

littlened
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 09 March 2006 - 02:05 PM

[!--quoteo(post=352860:date=Mar 8 2006, 02:32 PM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Mar 8 2006, 02:32 PM) View Post[/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:

FIRST PAGE
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


SECOND PAGE
$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");


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







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users