franzwarning Posted March 9, 2011 Share Posted March 9, 2011 Is there any way that I can get mysql_fetch_assoc only to run once? Here is my code: $query = mysql_query("SELECT * FROM items ORDER BY id DESC"); while ($row = mysql_fetch_assoc($query)) { $id = $row['id']; } Link to comment https://forums.phpfreaks.com/topic/230066-mysql_fetch_assoc-only-once/ Share on other sites More sharing options...
kenrbnsn Posted March 9, 2011 Share Posted March 9, 2011 Don't put in a while loop <?php $query = mysql_query("SELECT * FROM items ORDER BY id DESC"); if (mysql_numrows($query) > 0) { $row = mysql_fetch_assoc($query); $id = $row['id']; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/230066-mysql_fetch_assoc-only-once/#findComment-1184898 Share on other sites More sharing options...
franzwarning Posted March 9, 2011 Author Share Posted March 9, 2011 Guess I never thought of that.... thanks! Link to comment https://forums.phpfreaks.com/topic/230066-mysql_fetch_assoc-only-once/#findComment-1184900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.