开发者

PHP catalog, click on item image to display product details

I am trying to build a simple catalog displaying items from a mysql database. So far I can get the items to display in a list format including the images stored as a path in the items table in a field called "path".

I would like the ability to be able to click on the item image and it takes you to a dedicated page showing you the details of that product. The link would correspond to which ever item you click on based on the data in the item table.

So far I have the following code;

 <?php
session_start();
require "connect.php";
$date = date("d-M-Y");
$query =  "select * from item order by date && time asc limit 0,3";
$query2 = "select * from users where userid = ".$_SESSION['userid'];
$result = @mysql_query($query, $connection) 
or die ("Unable to perform query<br>$query");
 ?>

 <?php
  while($row= mysql_fetch_array($result))
  {
  ?>
 <?php echo $row['item'] ?>
 <?php echo $row['description'] ?>
 //Code for Image Link
 <a href='<a href='<?php echo $row['path']?>'><img src="<?php echo $row['path']?>
 <?php
 }
 ?>

The above code allows you to click on the image and it takes me to http://127.0.0.1/steal/%3Ca%20href=

However I don't know what I would need to enter in order for it to take me to a page that show开发者_C百科s the product? Please Help

Many Thanks


I don't know your database schema, so I'm taking some liberties here about your columns for the product. But, try this:

<a href="/product_page.php?product_id?<?php echo $row['id']?>"><img src="<?php echo $row['path']?"/></a>

I also am not sure what your product page URL is either, so change product_page.php to whatever template you are using to display your products.


You need to create another page called for example showProductsOrder.php that accepts the orderID and then does output the content.

showProductsOrder.php?orderID=1
<?php
      SELECT * FROM order WHERE orderID = $_GET['orderID']  
      while(fetch()) {
         //> Show product here
      }
?>

Also please don't use mysql_query. Use php.net/pdo

Addendum

<a href="showProductsOrder?orderID=<?php echo $row['id']?>">Show all products</a>


As yes123 said you would need to create another page, but i if you have a problem creating the link here is my suggested solution: Replace your link with:

<?php echo ("<a href='".$row['pagePath']."'><img src='".$row['imagePath']."' /></a>";?>

$row['pagePath'] is the page that it will load when the image is clicked on, and $row['imagePath'] is where the image is stored on your pc / server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜