I want to get the last row inserted into the database, but only get the first row. How I can fix it?
In phpmyadmin everything works:
But the code does not work:
Último precio: 28.41
Code:
$skip = 0;
$max = 1;
$id = 'gooo_id';
$q = $conn->prepare('SELECT * FROM price WHERE asin = :asin ORDER BY :id DESC LIMIT :skip, :max');
$q->bindValue(':asin', $asin, PDO::PARAM_STR);
$q->bindValue(':id', $id, PDO::PARAM_STR);
$q->bindValue(':skip', (int) trim($skip), PDO::PARAM_INT);
$q->bindValue(':max', (int) trim($max), PDO::PARAM_INT);
$q->execute();
$result_row = $q->fetchObject();
$lastprice = $result_row->price;
echo 'Último precio: '.$lastprice.'';
Solution
$skip = 0;
$max = 1;
$q = $conn->prepare('SELECT * FROM price WHERE asin = :asin ORDER BY gooo_id DESC LIMIT :skip, :max');
$q->bindValue(':asin', $asin, PDO::PARAM_STR);
$q->bindValue(':skip', (int) trim($skip), PDO::PARAM_INT);
$q->bindValue(':max', (int) trim($max), PDO::PARAM_INT);
$q->execute();
$result_row = $q->fetchObject();
$lastprice = $result_row->price;
echo 'Último precio: '.$lastprice.'';