johnsmith153 Posted March 20, 2009 Share Posted March 20, 2009 SELECT * FROM $tablename ORDER BY fieldName LIMIT 200 I want to select all records from a table, return in order of a set field, but only the first 200 records Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/ Share on other sites More sharing options...
trq Posted March 20, 2009 Share Posted March 20, 2009 And the problem is? Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789934 Share on other sites More sharing options...
johnsmith153 Posted March 20, 2009 Author Share Posted March 20, 2009 it doesn't work. I guess from your response it should work then? Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789936 Share on other sites More sharing options...
trq Posted March 20, 2009 Share Posted March 20, 2009 Providing $tablename is defined and fieldName exists, yes. Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789941 Share on other sites More sharing options...
johnsmith153 Posted March 20, 2009 Author Share Posted March 20, 2009 Go to : http://www.w3schools.com/sql/sql_tryit.asp ...and enter the below statement in the test: SELECT * FROM customers ORDER BY City LIMIT 5 It doesn't work. Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789948 Share on other sites More sharing options...
trq Posted March 20, 2009 Share Posted March 20, 2009 Thats because LIMIT is specific to mysql, there using some other sql database that doesn't support LIMIT. Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789950 Share on other sites More sharing options...
johnsmith153 Posted March 20, 2009 Author Share Posted March 20, 2009 What would be the alternative? I.e. what would you use on that site? Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789951 Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Share Posted March 20, 2009 You may want to post more of your code so that we can see more than just the one line... Because that one line should work providing that there isn't another issue within your code... Just a thought... Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789958 Share on other sites More sharing options...
johnsmith153 Posted March 20, 2009 Author Share Posted March 20, 2009 Here's your answer: SELECT TOP 5 * FROM $table ORDER BY $field Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-789963 Share on other sites More sharing options...
Malevolence Posted March 21, 2009 Share Posted March 21, 2009 *considerably flaming (sorry)* oh dear... *fixing that* You really should always post relevant php code such as the queries, defined variables etc. and any errors you recieved. That way people can help you a lot easier and you don't find yourself having to explain the problem at best. Link to comment https://forums.phpfreaks.com/topic/150410-what-wrong-with-select-from-tablename-order-by-fieldnm-limit-recordspertime/#findComment-790001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.