0

i have been teaching myself how to create a shopping cart with php, html and msql database through some tutorials the problem i have now is the msql code i need to use to display the products from the database..
i will appreciate your guidance

thanx

2
Contributors
1
Reply
8
Views
2 Years
Discussion Span
Last Post by gabrielcastillo
0

Get all your products
SELECT * from products_table

if you need single product, get by id
SELECT * FROM products_table WHERE id = '$id'

If you have categories and use index id's
SELECT * FROM products_table WHERE category_id = '$cat_id'

you can use a foreach loop to get all the records from your query and loop through and display the results:

If you are using procedureal style code with out html 
foreach($results as $result){
    echo $result['product_name'];
    echo $result['product_description'];
    echo $result['product_price'];
}


Using object orientented style with html
foreach($results as $result){
    echo '<p>' . $result->product_name . '</p>';
    echo '<p>' . $result->product_description . '</p>';
    echo '<p>' . $result->product_price . '</p>';
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.