vendredi 28 décembre 2018

How can I get the MAX product_id in MySQL & PHP from database table?

I want to have a function on my website where on the "New" page, it will show my single newest product, so it will need to take the last one added to the products table in SQL but I cannot figure out how to get the max and retrieve it onto the website with the price and image.

I am getting the 2 errors below, line 58 is the $pro_price line and 59 is the $pro_image:

Notice: Undefined index: product_price in /opt/lampp/htdocs/ecommerce/new.php on line 58

Notice: Undefined index: product_image in /opt/lampp/htdocs/ecommerce/new.php on line 59

Please also take a look at the link with the screenshot.

<?php

$get_pro = "select MAX(product_id) from products";

$run_pro = mysqli_query($con, $get_pro);

while($row_pro=mysqli_fetch_array($run_pro)){

    $pro_price = $row_pro['product_price'];
    $pro_image = $row_pro['product_image'];




Aucun commentaire:

Enregistrer un commentaire