Pull table from MySQL database
I have a script set up where a user submits data about him/her and it is put into a database. There are two tables inside the MySQL database, one for student accounts and one for managers. Each table has columns like firstname, lastname, address, city, state, zip etc. Is there a simple code I can use to pull the entire table out and display it in an HTML table? I think it should be simple but I have never done that before.
Thanks
Busy posted this at 22:49 — 1st April 2006.
He has: 6,151 posts
Joined: May 2001
You mean pull the contents from both tables and display all (or parts) of the results?
kinda like:
SELECT * FROM students a, managers b WHERE b.sudent_name='$name' AND b.managers_id=a.student_id;
teammatt3 posted this at 22:51 — 1st April 2006.
He has: 2,102 posts
Joined: Sep 2003
I just want to pull the whole table either student, or manager.
teammatt3 posted this at 23:08 — 1st April 2006.
He has: 2,102 posts
Joined: Sep 2003
I figured it out. This is the code I used
<?php
$db = mysql_connect(\"localhost\", \"root\");
mysql_select_db(\"itaa_accounts\",$db);
$result = mysql_query(\"SELECT * FROM accounts\",$db);
echo \"<table border=1>\n\";
echo \"<tr><td>First Name</td><td>Last Name</td><td>Address</td><td>City</td><td>State</td><td>Zip</td><td>Email</td></tr>\n\";
while ($myrow = mysql_fetch_row($result)) {
printf(\"<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n\",
$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[6], $myrow[7]);
}
echo \"</table>\n\";
?>
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.