Jump to content

Hyperlinks in PHP/MySQL


tracy

Recommended Posts

If I have a table in MySQL and generate a web page with the contents displayed using PHP, how hard is it to link one item in each row, for example:

say there is a lot of inventory displayed...

item one    description    photo
item two    description    photo
item three  description    photo

...you get the point...

if the photo is clicked I would like to hyperlink that to another php generated page with full details and more photos of this item.

I know I'd have to build the new page using PHP, no problem...it's the hyperlinking of the photo to said page that I don't know how to do.  I would think it's just a simple line of code, much like http hyperlinks but I'm not sure.  Any help is appreciated. 

Link to comment
https://forums.phpfreaks.com/topic/28767-hyperlinks-in-phpmysql/
Share on other sites

on the next PHP page you can call it by id or something (assuming u use id's on ur images). Make the urls come out when echoing from the database like so:

while($row = mysql_fetch_array($query)){
  echo "<a  href='this.php?id=" . $row['id'] . "'>". $row['name'] ."</a>";
}

id being t he id and 'name' being the name of course. Depends on how u named ur rows.

On this.php have something like:

<?php

$item_id = $_GET['id'];

// GET INFO FROM DATABASE BY ID
$query = mysql_query("SELECT * FROM table WHERE id='". $item_id ."'");

?>

You get the idea from there i hope.
are you saving the image information into the database? What exactly is the database information for?

I was thinking you had a field in your database with image information. Something like:
[code]
TABLE `images`

  id  |  name  |  description  |  image_link
  1  |  test  | this is a test | image.jpg
[/code]

If you do this then it would be easier. Just add the images to your database and you can even give them categories or whatever you'd like. The id would be "id" from the mysql database which would give the PHP script something to find the image by.
Each item in your product table should have a unique identifier. This could be a unique product code or, as is often used, an auto_incrementing row id field.

Whichever you have in your product table is the value that should go in the link so you jnow which item to display in the next page.

Archived

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

×
×
  • 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.