I have a table in a database. The primary field is ID Int(11) auto_increment. The public display of the table sorts the table by ID. I have a back-end member area where a member can log in and add a new record to the table. This new record displays on the front-end at the bottom because it is automatically inserted at the bottom of the table with the highest ID number.

As I said, the front-end display is set to sort by the primary field (ID). This is why new records are displayed at the bottom. I could change the sort to be based on one of the other fields in the table, but none of them suit what I would want after a member adds a new record.

Is there a way to allow the member who is entering the new record into the form to set where that new record will be displayed in the list on the front-end?

Recommended Answers

All 4 Replies

In your sql query
at last add line

order by id desc// it shows last record first

if not working put your code

Yes, I understand how to reverse the sort order. My question is how to insert a new record and set it to display, say 3rd on the list. I want the existing list to stay the same, but put in a new record at a point determined by the member who is creating the new record.

Hi dewhickey,

why don't you create another field? You could name it `priority` for example with a default value of ZERO and then do something like this:

SELECT * FROM `records` ORDER BY  `priority` DESC , `id` DESC LIMIT 0, 1

And when the user submits the form, you can put a check box like "Appear in front-end?" and if selected you set `priority` = 1

yes, you have to create one column "priority" in your table....

set priority to all existing records..

suppose new record or updated record set priority=1 to show this record on first place

mysql_query=("update records set priority=1 where id='$id'");

display records like

mysql_query=("SELECT * FROM records ORDER BY priority");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.