Issue
I am coding an e-commerce webpage with HTML, CSS, and JavaScript with the support of PHP and MySQL (mysqli). I have a grid of products on display, what I wanted was that each products when clicked - directs the user to one PHP page, that shows the product details of that particular product
Below shows the snippet of code from my index.php - I am using this PHP code to establish connection with the database, and grab data like the product name, price, etc.
<?php
session_start();
include("connection.php");
include("functions.php");
$user_data = check_login($con);
This one shows the products part of the same index PHP file - item1.php is to supposedly be the only products details page that shows it all.
<div class="col-1" onclick="location.href='item1.php';" style="cursor: pointer;">
<img src="Images/products/rooster18.png" alt="Rooster Chicken #18">
<h4>Rooster Chicken #18</h4>
<p>$17.65 <strike> $17.80 </strike></p>
</div>
<div class="col-1" onclick="location.href='item1.php';" style="cursor: pointer;">
<img src="Images/products/rewa full cream milk 1L Net.png" alt="rewa full cream milk 1L Net">
<h4>REWA Full Cream Milk 1L Net</h4>
<p>$2.52 <strike> $3.30 </strike></p>
</div>
please someone, briefly direct me here..I've seen some people explaining, but its not on point. thanks
Solution
as i understood the problem, you want to create a PHP page for every item that is in your database, i recommend to do a single page that get the URL and ask to the database for all the detail. With an exemple you will understand more easily.
In your main page (where every item is shown) we will imagine an item like this (this is the href
that is important to look: <a class="the_class_you_want" href="detailpage.php?productid=Irze545AZftes">beautiful keyboard</a>
(the product id is random and is stored on the database).
then on the 'detailpage.php' will $_GET['productid']
and check on the database if the product exist, if yes, it will retrieve every information that he will need (price, manufacturer, full name, and every other information) to display them on the page. Then you can organise every information on the page.
Hope this helped.
Answered By - Tenteur
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.