L
L
lexa_gorchakov192018-09-19 15:32:59
SQL
lexa_gorchakov19, 2018-09-19 15:32:59

How can I add a record to the top of the database?

Here is my code for adding a topic to the forum.

$query = mysqli_query($connection, "INSERT INTO `forum`(`title`, `description`, `category`, `author`, `price`) VALUES ('$title','$description','$category', '$author', '$price')");

How to make it so that this topic is added to the beginning of the database, and not to the end? Or how to display them, but so that the last would be displayed???
PS in php and sql newbie, if this is not possible then just write)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lexa_gorchakov19, 2018-09-19
@lexa_gorchakov19

Perhaps you need to make sure that the questions are sorted in descending order of id in the database....

P
ponaehal, 2018-09-20
@ponaehal

the very concepts of "database start" and "database end" are absolutely wrong. Data in most relational databases is stored in an unsorted form. The DBMS itself decides "where in the table" to insert the record.
As colleagues have already correctly said above, it is correct to add the phrase ORDER BY <sort field> <sort order - ASC|DESC> to the query that displays your data in the user interface.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question