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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Imtehbegginer Posted November 6, 2006 Author Share Posted November 6, 2006 Awsome! Thanks alot. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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.