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. Quote Link to comment Share on other sites More sharing options...
delickate Posted August 11, 2008 Share Posted August 11, 2008 send your code you write. Quote Link to comment 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"; } } } 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.