zamp0e Posted June 1, 2009 Share Posted June 1, 2009 I'm having huge problems learning the sql syntax for INSERT, and how to properly use it to get an output in the browser. For far too long now I have tried to simply print out the first 5 rows of my database, I have searched the web for tutorials on how to do this, and they all say the same; something like this: SELECT * FROM table_name That's all I've found, I know I have to declare it and stuff like that but I just don't know how. So the question is, How do I get my browser to print out the 5 first lines of my database ? Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/ Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 First 5 records according to what? (id, date, etc...) It would look something like: SELECT * FROM table LIMIT 5 (You will need ORDER BY if you want to get the first/last 5 according to a specific column) Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847257 Share on other sites More sharing options...
zamp0e Posted June 1, 2009 Author Share Posted June 1, 2009 I'd like to print out 5 rows where the ID is (1,2,3,4,5) The thing I tried was something like: SELECT name FROM iqtable WHERE ID=1 echo "$name" SELECT name FROM iqtable WHERE ID=2 echo "$name" SELECT name FROM iqtable WHERE ID=3 echo "$name" SELECT name FROM iqtable WHERE ID=4 echo "$name" SELECT name FROM iqtable WHERE ID=5 echo "$name" Obviously, this is nowhere near right, as it's not working, and just looks plain stupid. Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847267 Share on other sites More sharing options...
Ken2k7 Posted June 1, 2009 Share Posted June 1, 2009 What's wrong with Maq's SQL? It should work. Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847271 Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 Use this then: SELECT name FROM iqtable ORDER BY id LIMIT 5 Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847278 Share on other sites More sharing options...
Ken2k7 Posted June 1, 2009 Share Posted June 1, 2009 I guess I assumed the value of ID wouldn't change. As in, a row with ID 10 wouldn't be before a row with ID 5. Maq - I think the column is ID, not id. Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847282 Share on other sites More sharing options...
zamp0e Posted June 1, 2009 Author Share Posted June 1, 2009 The thin is, only writing that line is not printing out anything on the screen, and I have no idea how to continue untill I actully get the output. Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847285 Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 There's examples in the manual - mysql_query. I guess I assumed the value of ID wouldn't change. As in, a row with ID 10 wouldn't be before a row with ID 5. Maq - I think the column is ID, not id. Ah yes, 'ID' not 'id'. Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847289 Share on other sites More sharing options...
zamp0e Posted June 1, 2009 Author Share Posted June 1, 2009 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847292 Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 Thanks NP, the query should be the hardest part, and you've already got that done. If you have any questions, I would probably create a new thread in the 'PHP Help' section. So if the query is solved, please mark as so. Quote Link to comment https://forums.phpfreaks.com/topic/160541-solved-problems-with-select/#findComment-847297 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.