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!! Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/ 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']; ?> Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524030 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 Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524033 Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 Correct Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524034 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? Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524035 Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 I just gave you the code. Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524036 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 ; Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524037 Share on other sites More sharing options...
dezkit Posted April 22, 2008 Author Share Posted April 22, 2008 ah thank you Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524042 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. Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524046 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 Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524047 Share on other sites More sharing options...
p2grace Posted April 22, 2008 Share Posted April 22, 2008 Ah sorry about that Link to comment https://forums.phpfreaks.com/topic/102346-solved-5-mysql/#findComment-524051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.