~n[EO]n~ Posted October 29, 2007 Share Posted October 29, 2007 What query needs to be written to fetch the data except the first record, the id is auto increment but if the users delete the first lowest id then second id must not be shown. $tbl=new Model; $sSqlQuery="select * from ".ACHIEVEMENTS_TABLE." WHERE achievements_lang='EN' AND 1=1"; Any Idea ??? Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/ Share on other sites More sharing options...
MadTechie Posted October 29, 2007 Share Posted October 29, 2007 if you dealing with auto increment then use mysql_insert_id mysql_insert_id mysql_insert_id — Get the ID generated from the previous INSERT operation either that or use limit 1,1 sort by id Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380277 Share on other sites More sharing options...
~n[EO]n~ Posted October 29, 2007 Author Share Posted October 29, 2007 Thanks for you reply but i don't need this mysql_insert_id your or part worked but while using LIMIT 1,1 $sSqlQuery="select * from ".ACHIEVEMENTS_TABLE." WHERE achievements_lang='EN' LIMIT 1,1 ORDER BY id"; it shows from the second record but limit is 1, I need all other records except the first record, is that possible Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380422 Share on other sites More sharing options...
trq Posted October 29, 2007 Share Posted October 29, 2007 You could try... $sSqlQuery="SELECT COUNT(id) as ttl, * FROM ".ACHIEVEMENTS_TABLE." WHERE achievements_lang='EN' LIMIT 1,ttl ORDER BY id"; Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380427 Share on other sites More sharing options...
~n[EO]n~ Posted October 29, 2007 Author Share Posted October 29, 2007 Sorry, it didn't worked $sSqlQuery="SELECT COUNT(id) as ttl, * FROM ".ACHIEVEMENTS_TABLE." WHERE achievements_lang='EN' LIMIT 1,ttl ORDER BY id"; What is ttl here, While I tried this on other table, SELECT COUNT(co_id) as ttl, * FROM contact LIMIT 1,ttl ORDER BY co_id; it shows error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM contact LIMIT 1,ttl ORDER BY co_id' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380432 Share on other sites More sharing options...
trq Posted October 29, 2007 Share Posted October 29, 2007 Instead of using the wildcard *, try actually defining each field. This is always recommended anyway. Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380437 Share on other sites More sharing options...
~n[EO]n~ Posted October 29, 2007 Author Share Posted October 29, 2007 Ok, I used the field name still not working SELECT COUNT( co_id ) AS ttl, co_fname, co_lname FROM contact ORDER BY co_id LIMIT 1 , ttl As far as i have understood about AS ttl, it is to count the total rows and store in ttl and limited to total rows, am I right ? But it is showing the same error near ttl Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380444 Share on other sites More sharing options...
sasa Posted October 29, 2007 Share Posted October 29, 2007 try SELECT * FROM contact WHERE co_id>(SELECT MIN(co_id) FROM contact) Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380491 Share on other sites More sharing options...
~n[EO]n~ Posted October 30, 2007 Author Share Posted October 30, 2007 Thanks sasa your code worked Thanks to all.... Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380904 Share on other sites More sharing options...
trq Posted October 30, 2007 Share Posted October 30, 2007 Im afraid to say though that it won't always be reliable. There is nothing to stop mysql from reusing an index if its generated via auto_increment. auto_increment should not be relied upon for order. Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380908 Share on other sites More sharing options...
~n[EO]n~ Posted October 30, 2007 Author Share Posted October 30, 2007 Im afraid to say though that it won't always be reliable. There is nothing to stop mysql from reusing an index if its generated via auto_increment. auto_increment should not be relied upon for order. Do you mean for long term running of the site it will not be reliable ? What are other alternatives ? I am already afraid... Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-380929 Share on other sites More sharing options...
~n[EO]n~ Posted October 30, 2007 Author Share Posted October 30, 2007 Why this does not work ? SELECT COUNT( co_id ) AS ttl, co_fname, co_lname FROM contact ORDER BY co_id LIMIT 1 , ttl It shows error near ttl Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-381064 Share on other sites More sharing options...
aschk Posted October 30, 2007 Share Posted October 30, 2007 Because ttl is an alias, and you also can't use an alias in the LIMIT clause especially when it's inline with the query. Nor can you use a subquery in the limit clause (before you try it). Quote Link to comment https://forums.phpfreaks.com/topic/75193-fetching-data-from-table-except-the-first-record/#findComment-381070 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.