dezkit Posted April 22, 2008 Share Posted April 22, 2008 is there a way to only echo the 5 latest mysql rows? <?php // Make a MySQL Connection $query = "SELECT * FROM matches"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['home_team']. " vs ". $row['guest_team']; echo " : " . $row['result']; ?> please don't tell me the function i should use, instead, edit my code, thank you!! Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 Here you go <?php // Make a MySQL Connection $query = "SELECT * FROM matches ORDER BY `id` DESC LIMIT 0,5"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['home_team']. " vs ". $row['guest_team']; echo " : " . $row['result']; ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 That's assuming you are using the `id`(INT)NOT NULL AUTO INCREMENT field Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 Correct Quote Link to comment Share on other sites More sharing options...
dezkit Posted April 22, 2008 Author Share Posted April 22, 2008 ok, i will use it id(int) now, what's the code again? Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 I just gave you the code. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 in phpmyadmin (or whatever mysql app you are using) ALTER TABLE `table_name` ADD `id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ; Quote Link to comment Share on other sites More sharing options...
dezkit Posted April 22, 2008 Author Share Posted April 22, 2008 ah thank you Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 Could you mark the topic as solved once you confirm it's working Thank you. Quote Link to comment Share on other sites More sharing options...
dezkit Posted April 22, 2008 Author Share Posted April 22, 2008 i did, 2 seconds before you posted that post Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 Ah sorry about that 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.