I am storing forum post into a database and need to select the last row which got added.
I have a id field which is on auto_increment
so what I need to do is do a select were the id is the highest and the topic = 1
.
Here is what I got so far which does not echo out anything.
$statementt56 = $db->prepare("SELECT * FROM topics WHERE topic_cat = '1' ORDER BY topic_id DESC LIMIT 1 ");
$battle_gett56 = $statementt56->fetch();
echo $battle_gett56['topic_subject'] ;
What am i doing wrong ?
I have fixed this by using this code
$statementt = $db->prepare("SELECT * FROM topics WHERE topic_cat = '1' ORDER BY topic_id DESC LIMIT 1 ");
$statementt->execute(array());
$battle_gett = $statementt->fetch(); // Use fetchAll() if you want all results, or just iterate over the statement, since it implements Iterator
echo $battle_gett['topic_subject'] ;
all works perfect now