ali_254 Posted March 27, 2021 Share Posted March 27, 2021 hi... i have a table ... i add and remove data in the table...when i add new record , information add to center of the table ! whats problem? i want add data in first of table. please guide me.thanks Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/ Share on other sites More sharing options...
kicken Posted March 27, 2021 Share Posted March 27, 2021 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585442 Share on other sites More sharing options...
ali_254 Posted March 27, 2021 Author Share Posted March 27, 2021 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? Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585443 Share on other sites More sharing options...
gw1500se Posted March 27, 2021 Share Posted March 27, 2021 Post your query. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585444 Share on other sites More sharing options...
ali_254 Posted March 27, 2021 Author Share Posted March 27, 2021 $sql = "SELECT *,news.id as nid FROM news left JOIN category ON category.id=news.catid LIMIT $lim OFFSET $offset "; Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585445 Share on other sites More sharing options...
Barand Posted March 27, 2021 Share Posted March 27, 2021 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 | +---------+-----------+----------+----------+------------+ 1 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585446 Share on other sites More sharing options...
ali_254 Posted March 27, 2021 Author Share Posted March 27, 2021 thanks mr Barand. are you can edit my cod AND add your Suggested code? $sql = "SELECT *,news.id as nid FROM news left JOIN category ON category.id=news.catid LIMIT $lim OFFSET $offset "; Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585447 Share on other sites More sharing options...
Barand Posted March 27, 2021 Share Posted March 27, 2021 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; 1 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585449 Share on other sites More sharing options...
ali_254 Posted March 28, 2021 Author Share Posted March 28, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585454 Share on other sites More sharing options...
kicken Posted March 28, 2021 Share Posted March 28, 2021 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585456 Share on other sites More sharing options...
ali_254 Posted March 28, 2021 Author Share Posted March 28, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585457 Share on other sites More sharing options...
ali_254 Posted April 2, 2021 Author Share Posted April 2, 2021 I found a solution for this problem... change table engine to=InnoDB Quote Link to comment https://forums.phpfreaks.com/topic/312391-problem-adding-information-at-the-end-of-the-table-or-at-the-beginning-of-the-table/#findComment-1585565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.