shlomikalfa Posted October 28, 2007 Share Posted October 28, 2007 hello, i've been wandering if there's a way to read the index of a table in a sort and easy command instead of using this: $sql = "SELECT ID FROM `downloads` WHERE 1"; $result = mysql_query($sql, $link); if (!$result) { echo "Error: could not query the database"; echo 'MySQL Error: ' . mysql_error(); exit; } $rownum = mysql_num_rows($result); PS, ID - is an indexed collumn which is auto-incremented. Thanks in advance!!! Link to comment https://forums.phpfreaks.com/topic/75145-solved-getting-the-number-of-entries-in-a-table-reading-its-index/ Share on other sites More sharing options...
teng84 Posted October 28, 2007 Share Posted October 28, 2007 $sql = "SELECT count(ID) as my_id FROM `downloads`; $result = mysql_fetch_assoc(mysql_query($sql, $link)); echo $result['my_id']; hmm is that what you mean? Link to comment https://forums.phpfreaks.com/topic/75145-solved-getting-the-number-of-entries-in-a-table-reading-its-index/#findComment-380033 Share on other sites More sharing options...
shlomikalfa Posted October 28, 2007 Author Share Posted October 28, 2007 that does the trick, but so does mine... - isn't there a way to access and read the last index directly ? Link to comment https://forums.phpfreaks.com/topic/75145-solved-getting-the-number-of-entries-in-a-table-reading-its-index/#findComment-380039 Share on other sites More sharing options...
teng84 Posted October 28, 2007 Share Posted October 28, 2007 echo mysql_insert_id();<-- returns the last id try Link to comment https://forums.phpfreaks.com/topic/75145-solved-getting-the-number-of-entries-in-a-table-reading-its-index/#findComment-380045 Share on other sites More sharing options...
Barand Posted October 29, 2007 Share Posted October 29, 2007 mysql_insert_id() returns the id of the last record inserted during the current connection. If you haven't inserted a new record since you last connected to the server it will return 0. Link to comment https://forums.phpfreaks.com/topic/75145-solved-getting-the-number-of-entries-in-a-table-reading-its-index/#findComment-380093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.