Product page

ok I made an admin page where I can add items to my ‘products’ table in myphpadmin.

the fields are:

id
product_name
price
detail
category
subcategory
date_added

I want to make a page where users can view a list of the products

I don’t want to make a page for each product I just want it to get the products and post them in the page temporarily

I also want to make a search bar where I can search for products and it would post the related products

I have no idea how to make that so please help me, I’ve just started using php

thankyou :slight_smile:

Hello lahsoona,
for listing products you have to simply run select query in you database table and display data.
See below code For list products with their price.
[php]

<? $con = mysql_connect("localhost", "username","password") or die('Sorry, could not connect to database server'); mysql_select_db("databsaename", $con) or die('Sorry, could not connect to database'); if (!$con) { echo "

Sorry, we cannot process your request at this time, please try again later

\n"; } else { $result = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($result)) { echo $row['product_name'] . " " . $row['price']; echo "
"; } } ?>

[/php]

For search bar do below code

[php]

<? $con = mysql_connect("localhost", "username","password") or die('Sorry, could not connect to database server'); mysql_select_db("databsaename", $con) or die('Sorry, could not connect to database'); if (!$con) { echo "

Sorry, we cannot process your request at this time, please try again later

\n"; } else { if($REQUEST_METHOD == "POST") { if(!empty($_POST['product_name'])) { $sql = 'SELECT * FROM products WHERE product_name LIKE "%'.$_POST['product_name'].'%"'; $search_result = mysql_query($sql); while($row_search = mysql_fetch_array($search_result)) { echo $row_search['product_name'] . " " . $row_search['price']; echo "
"; } } } } ?> Search: [/php]

I hope this will helpful for you.
Reply Your feed back…
SR

Sponsor our Newsletter | Privacy Policy | Terms of Service