snuggles79 Posted December 12, 2008 Share Posted December 12, 2008 This is probably really simple to achieve but I've been going round and round in circles and now it's doing my head in ??? How do I display everything that's in an SQL database on a PHP webpage as a table? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/136724-solved-displaying-sql-database-on-php-page/ Share on other sites More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 http://us.php.net/manual/en/function.mysql-fetch-array.php <?php mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error());// connect to db mysql_select_db("mydb"); $result = mysql_query("SELECT id, name FROM mytable"); //ur query here while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { printf("ID: %s Name: %s", $row["id"], $row["name"]);//echo out here } mysql_free_result($result); ?> Ted Quote Link to comment https://forums.phpfreaks.com/topic/136724-solved-displaying-sql-database-on-php-page/#findComment-714018 Share on other sites More sharing options...
snuggles79 Posted December 12, 2008 Author Share Posted December 12, 2008 Thanks for that Ted but I think I must be in dumb mode tonight. I get the first bit because that just connects to the database. But what does id, name mean? And what should I be putting as my id, name if I want it to display all columns of all records? Quote Link to comment https://forums.phpfreaks.com/topic/136724-solved-displaying-sql-database-on-php-page/#findComment-714037 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 id and name refers to the column, for each table u would have columns and rows, rows are just ur entries, and columns r different variables u can store for each entry: idname ted_chou12Ted snuggles79snuggles Ted Quote Link to comment https://forums.phpfreaks.com/topic/136724-solved-displaying-sql-database-on-php-page/#findComment-714040 Share on other sites More sharing options...
snuggles79 Posted December 12, 2008 Author Share Posted December 12, 2008 All done now Ted thank you Quote Link to comment https://forums.phpfreaks.com/topic/136724-solved-displaying-sql-database-on-php-page/#findComment-714134 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.