Imtehbegginer Posted November 6, 2006 Share Posted November 6, 2006 Hey,I was just wondering, how to select, only the TOP 5 rows. Not all of them, just the top 5. Can anyone tell me how to do this? Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/ Share on other sites More sharing options...
marked Posted November 6, 2006 Share Posted November 6, 2006 Hi,If you're talking about using MySQL you can write SELECT * FROM table LIMIT 5That will get you the top 5 rows. Of course you can add in any WHERE, ORDER BY etc that you need.Thanksmark Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/#findComment-120124 Share on other sites More sharing options...
Imtehbegginer Posted November 6, 2006 Author Share Posted November 6, 2006 Awsome! Thanks alot. Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/#findComment-120125 Share on other sites More sharing options...
Imtehbegginer Posted November 6, 2006 Author Share Posted November 6, 2006 [code]<?php include 'config.php'; $result = mysql_query("SELECT char_name FROM characters LIMIT 5") or die(mysql_error()); $echos = $row['char_name']; echo $echos;?>[/code]That's my code, my config.php file connects to mysql. It doesnt show anything, just shows a blank page. Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/#findComment-120127 Share on other sites More sharing options...
marked Posted November 6, 2006 Share Posted November 6, 2006 Hey,you need to use something like mysql_fetch_array like so:[code]$result = mysql_query("SELECT char_name FROM characters LIMIT 5") or die(mysql_error());while($row = mysql_fetch_array($result)) { $echos .= $row['char_name'];}echo $echos;[/code]This will also append the results to the $echos variable, rather than keep overwriting it.Thanks,mark Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/#findComment-120129 Share on other sites More sharing options...
Imtehbegginer Posted November 6, 2006 Author Share Posted November 6, 2006 That works,Now I getBrett19DeathcodeGenesisStrikeXRoseBot All of the rows together. How can I split them up? Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/#findComment-120133 Share on other sites More sharing options...
marked Posted November 6, 2006 Share Posted November 6, 2006 throw in a line break or however you want to split them like so:[code]$echoes .= $row['char_name'] . '<br />';[/code]This will append a line break to the end of every row.Thanks,mark Link to comment https://forums.phpfreaks.com/topic/26266-selecting-certain-rows/#findComment-120134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.