Jump to content

Problem adding information at the end of the table or at the beginning of the table


ali_254

Recommended Posts

It doesn't matter where in the table the data is stored.  When you query your data you want to specify an ORDER BY clause to define what order it will be returned in.

If you want the records to display in the order the were added, make sure you have a field that records what date and time the record was added and sort by that field.

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, kicken said:

It doesn't matter where in the table the data is stored.  When you query your data you want to specify an ORDER BY clause to define what order it will be returned in.

If you want the records to display in the order the were added, make sure you have a field that records what date and time the record was added and sort by that field.

 

 

thank you.

When I add a query And display it in a grid , Unfortunately The information is not displayed correctly again...

Actually , Information when added not stored properly...Is there a solution to this problem? Or should the "query" solve the problem?

 

Quote

make sure you have a field that records what date and time the record was added and sort by that field.

Do you have an example and source code for this?

grid.jpg

Link to comment
Share on other sites

26 minutes ago, ali_254 said:

Do you have an example and source code for this?

If I just get the records from my user table they appear in the order they are stored

SELECT user_id
     , firstname
     , lastname
     , username
     , dob
FROM user;

+---------+-----------+----------+----------+------------+
| user_id | firstname | lastname | username | dob        |
+---------+-----------+----------+----------+------------+
|       1 | Peter     | Dowt     | peterd   | 2009-12-21 |
|       2 | Laura     | Norder   | lauran   | 2010-10-22 |
|       3 | Tom       | DiCanari | tomd     | 2007-10-24 |
|       4 | Scott     | Chegg    | cheggs   | 2008-03-08 |
|       5 | Polly     | Vinyl    | pollyv   | 2010-12-15 |
|       6 | Polly     | Styrene  | pollys   | 2005-08-20 |
|       7 | Tom       | Catt     | tomc     | 2011-02-17 |
+---------+-----------+----------+----------+------------+

However, I want to list then in order of their dates of birth (dob column) so add an order by clause to the query

SELECT user_id
     , firstname
     , lastname
     , username
     , dob
FROM user
ORDER BY dob;

+---------+-----------+----------+----------+------------+
| user_id | firstname | lastname | username | dob        |
+---------+-----------+----------+----------+------------+
|       6 | Polly     | Styrene  | pollys   | 2005-08-20 |
|       3 | Tom       | DiCanari | tomd     | 2007-10-24 |
|       4 | Scott     | Chegg    | cheggs   | 2008-03-08 |
|       1 | Peter     | Dowt     | peterd   | 2009-12-21 |
|       2 | Laura     | Norder   | lauran   | 2010-10-22 |
|       5 | Polly     | Vinyl    | pollyv   | 2010-12-15 |
|       7 | Tom       | Catt     | tomc     | 2011-02-17 |
+---------+-----------+----------+----------+------------+

 

  • Like 1
Link to comment
Share on other sites

I am not psychic.

Only you currently know what sequence you want.

Only you know which column you would need to sort on to get that desired sequence (and if such a column even exists).

Here's a start...

SELECT *                                              -- DON'T use *, specify the columns you want.
     , news.id as nid 
FROM news 
     LEFT JOIN category ON category.id=news.catid 
ORDER BY ???????????????????     
LIMIT $lim 
OFFSET $offset;

 

  • Like 1
Link to comment
Share on other sites

thank you.

Is there a solution information when entering the bank Be sorted?  Without change in "query" codes?

In fact, any data that enters the table , Must be at the bottom or top of the table....Eventually, the problem is solved

 

Link to comment
Share on other sites

8 hours ago, ali_254 said:

Is there a solution information when entering the bank Be sorted?  Without change in "query" codes?

Databases don't have a concept of order when inserting data.  The data is stored in whatever location it will fit.

You can only define an order when you're reading data back out of the database using a SELECT query and you do that by using an ORDER BY clause in your query. 

So if you want your data to display in a specific order, you MUST change your query to include an ORDER BY clause that specifies the ordering you want.

  • Like 1
Link to comment
Share on other sites

43 minutes ago, kicken said:

Databases don't have a concept of order when inserting data.  The data is stored in whatever location it will fit.

You can only define an order when you're reading data back out of the database using a SELECT query and you do that by using an ORDER BY clause in your query. 

So if you want your data to display in a specific order, you MUST change your query to include an ORDER BY clause that specifies the ordering you want.

thank you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.