Display related products question.


hi,

i need "people viewed viewed these?" type of thing.  you've seen them on shopping carts.  pretty common i'm not sure logic.

 

i'm working php & mysql on dynamically populated page.  page contain product database.

so if product being viewed category a, want display 4 random thumbnail images category a..  likewise, if current product category b, want thumbnails category b , on...

i've got lot of categories.  what's best way of doing this?

 

 

nancy o.

you need 'product_category' column in database.

 

when initial product details 'product_category' , assign variable:

 

$getproductdetails = $conn->query("select * products product_id='$product_id'") or die($conn->error);

$getproductdetails = $getproductdetails->fetch_assoc();

$product_category = $getproductdetails['product_category'];

 

 

then check $product_category variable against database 'product_category' column:

 

<?php if($getproductdetails['product_category'] == $product_category) { ?>

 

<?php

// 4 random products show category products table

$selectrandomproducts = $conn->query("select * products product_category = '$product_category' order rand() limit 4") or die($conn->error);

?>

 

 

<?php } ?>

 

 

then echo out results of $selectrandomproducts varible using while loop:

 

<?php while($row = $selectrandomproducts->fetch_assoc()) { ?>

 

<?php echo $row['product_name']; ?>

<?php echo $row['product_price']; ?>

 

<?php } ?>

 

 

that should need be.



More discussions in Dreamweaver support forum


adobe

Comments

Popular posts from this blog

Illustrator CS6 Ocurrío un error E/S en el archivo.

Why is os_ViewContainer running?

Animate - problem with duplicating scripts after loop