pdo select latest from table

kevstarlive

I have this code to display from my Mysql database.

class cast {
public function fetch_all(){
    global $pdo;
      $query = $pdo->prepare("SELECT * FROM podcast limit 1");
      $query->execute();
return $query->fetchAll();
              }

this code does indeed display only 1 result as per the LIMIT 1 bit.

but this diaplays my 1st post.

my posts have a numeric ID under the name of cast_id

How can I get the code above to display the latest addition (for example the highest number in cast_id) and not the first one?

please help.

thank you.

Darren

Try something like

class cast {
public function fetch_all(){
    global $pdo;
      $query = $pdo->prepare("SELECT * FROM podcast ORDER BY cast_id DESC LIMIT 1");
      $query->execute();
return $query->fetchAll();
              }

That should fetch the latest one.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select latest from joined table excluding duplicates

From Dev

select latest duplicate record from table MySQL

From Dev

php/pdo/mysql accessing selected row from a select * in html table

From Dev

MySQL / PDO - Select from other table (Join statement)

From Dev

php/pdo/mysql accessing selected row from a select * in html table

From Dev

SELECT 4 latest rows from Oracle table with join

From Dev

Select 10 latest comments with unique author from MySQL table

From Dev

how to select latest record from table by using Group by statements

From Dev

select latest 20 records under each category from one table

From Dev

how to select latest record from table by using Group by statements

From Dev

SQL Select latest result from table where keyword = and competitor =

From Dev

Select the latest message thread values from a table using sql

From Dev

How to select latest date from this query (not in a existing table)?

From Dev

"SELECT :parameter FROM .." in PDO

From Dev

Select rows from a table based on results from two other tables in mySQL using PDO

From Dev

select the latest date from joins

From Dev

MySQL latest record from table

From Dev

select rows which has latest date without repetition from two joined table?

From Dev

Select the latest 3 records for each ID in a table

From Dev

MySQL Select Latest Date - Single Table

From Dev

select * from (select * from table)

From Dev

SELECT data from DB using PDO and sessions

From Dev

SELECT latest data from 2 joined tables

From Dev

MySQL SELECT latest record from a subquery with UNION

From Dev

Mysql - Order in group by , select latest from group

From Dev

select latest 3 records from sql database

From Dev

Select latest topic from a category (SQL and PHP)

From Dev

How to select latest date from database in MySQL

From Dev

select latest 3 records from sql database

Related Related

  1. 1

    Select latest from joined table excluding duplicates

  2. 2

    select latest duplicate record from table MySQL

  3. 3

    php/pdo/mysql accessing selected row from a select * in html table

  4. 4

    MySQL / PDO - Select from other table (Join statement)

  5. 5

    php/pdo/mysql accessing selected row from a select * in html table

  6. 6

    SELECT 4 latest rows from Oracle table with join

  7. 7

    Select 10 latest comments with unique author from MySQL table

  8. 8

    how to select latest record from table by using Group by statements

  9. 9

    select latest 20 records under each category from one table

  10. 10

    how to select latest record from table by using Group by statements

  11. 11

    SQL Select latest result from table where keyword = and competitor =

  12. 12

    Select the latest message thread values from a table using sql

  13. 13

    How to select latest date from this query (not in a existing table)?

  14. 14

    "SELECT :parameter FROM .." in PDO

  15. 15

    Select rows from a table based on results from two other tables in mySQL using PDO

  16. 16

    select the latest date from joins

  17. 17

    MySQL latest record from table

  18. 18

    select rows which has latest date without repetition from two joined table?

  19. 19

    Select the latest 3 records for each ID in a table

  20. 20

    MySQL Select Latest Date - Single Table

  21. 21

    select * from (select * from table)

  22. 22

    SELECT data from DB using PDO and sessions

  23. 23

    SELECT latest data from 2 joined tables

  24. 24

    MySQL SELECT latest record from a subquery with UNION

  25. 25

    Mysql - Order in group by , select latest from group

  26. 26

    select latest 3 records from sql database

  27. 27

    Select latest topic from a category (SQL and PHP)

  28. 28

    How to select latest date from database in MySQL

  29. 29

    select latest 3 records from sql database

HotTag

Archive