vang163 Posted August 11, 2008 Share Posted August 11, 2008 hi, can you show me how to write a function that display all data in database, irregardless of the number of columns and rows in the database, thanks. I've tried for 2 days but failed. Link to comment https://forums.phpfreaks.com/topic/119101-display-data-in-a-table/ Share on other sites More sharing options...
delickate Posted August 11, 2008 Share Posted August 11, 2008 send your code you write. Link to comment https://forums.phpfreaks.com/topic/119101-display-data-in-a-table/#findComment-613257 Share on other sites More sharing options...
vang163 Posted August 11, 2008 Author Share Posted August 11, 2008 function displayData($tableName) { $sql = "SELECT * FROM $tableName"; $result = mysql_query($sql) or die("Query Failed."); $count = mysql_num_rows($result); $number_of_column = mysql_num_fields($result); if ($count == 0) { echo 'No matches of your criteria.'; } else if ($count > 0) { for($j = 0; $j < $count; $j++) { echo " <tr>\r"; for($i = 0; $i < $number_of_column; $i++) { echo " <td>" . mysql_fetch_row($j, $i) . "</td>\r"; } echo " </tr>\r"; } } } Link to comment https://forums.phpfreaks.com/topic/119101-display-data-in-a-table/#findComment-613266 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.