Zaynt Posted February 16, 2009 Share Posted February 16, 2009 I have a database with zip-codes and the city-names that go with those zip-codes. I am making an easy search query into the database, but I can't quite figure out how to solve this problem...In the searchfield the user can choose how many rows to return from a certain point. $startrange = 7300; //this is the value of zipcode where the query will start $returnrows = 50; //how many rows to return after that point in total (including the row $strartrange) $query = "SELECT * FROM zipcodes_and_names WHERE zipcode = $startrange"; that query will just return the row with the value of $startrange, but I also want to return the next 49 rows.. Do I have to use several query's to do this? any ideas? Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/ Share on other sites More sharing options...
Stephen68 Posted February 16, 2009 Share Posted February 16, 2009 You need to look into paging and limits in your query http://php.about.com/od/mysqlcommands/g/Limit_sql.htm Just google mysql limits or paging and you should get all kind of good info. Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/#findComment-763356 Share on other sites More sharing options...
Zaynt Posted February 16, 2009 Author Share Posted February 16, 2009 Ok so I have to have two query's: the first query I have to return the row numer of the row where zipcode = $startrange how do I do that? Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/#findComment-763426 Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Why not SELECT * FROM zipcodes_and_names WHERE zipcode >= $startrange ORDER BY zipcode LIMIT 50 Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/#findComment-763430 Share on other sites More sharing options...
Zaynt Posted February 16, 2009 Author Share Posted February 16, 2009 because the value of the zip-codes don't go eg. 7300,7301,7302,7303, they go eg. 7303, 7330, 7350. So if I return the values of zipcodes between eg. 7300 and 7350, I get 3 rows, not 50.... Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/#findComment-763448 Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 But this query will just return 50 rows starting from given zipcode. Exactly what you want if I understand correctly. Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/#findComment-763450 Share on other sites More sharing options...
Zaynt Posted February 16, 2009 Author Share Posted February 16, 2009 Ahh, yes youre right! thank you very much! Just didn't understand it at first...I get it now. Thanks again man, just what I was looking for! Link to comment https://forums.phpfreaks.com/topic/145410-solved-mysql-query-return-range-of-rows-from-a-certain-point/#findComment-763464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.