vetman Posted April 23, 2008 Share Posted April 23, 2008 I have this acript: <?php // Make a MySQL Connection include 'config.php'; $con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db("rwts_webmaster") or die(mysql_error()); echo "Connected to Database <br>"; // Retrieve all the data from the "ufm_form_data" table $result = mysql_query("SELECT * FROM ufm_form_data") or die(mysql_error()); // store the record of the "ufm_form_data" table into $row echo "<table border='1' width='800'>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><th>Company</th><td> {$row['company']}</td><tr>"; echo "<tr><th>FirstName</th><td> {$row['firstName']}</td><tr>"; echo "<tr><th>LastName</th><td> {$row['lastName']}</td><tr>"; echo "<tr><th>Email</th><td> {$row['email']}</td><tr>"; echo "<tr><th>Address</th><td> {$row['address1']}</td><tr>"; echo "<tr><th>City</th><td> {$row['city']}</td><tr>"; echo "<tr><th>State</th><td> {$row['state']}</td><tr>"; echo "<tr><th>Zip Code</th><td> {$row['postalCode']}</td><tr>"; echo "<tr><th>Phone</th><td> {$row['phone']}</td><tr>"; echo "<tr><th>Info</th><td> {$row['info']}</td><tr>"; echo "<tr><th>Quote</th><td> {$row['quote']}</td><tr>"; echo "<tr><th>Comments</th><td> {$row['comments']}</td><tr>"; } echo "</table>"; It shows up in a table, vertically, down the page, but it includes all the data. I want to break up the data by $id, $id1 table $id2 table $id3 table I guess in other words I want it to loop thru the total number of $id's showing each in it's own table. I hope this explains it right. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/102551-i-want-tables-for-my-data-by-id/ Share on other sites More sharing options...
derrick1123 Posted April 23, 2008 Share Posted April 23, 2008 Try looking up PHP loops... Quote Link to comment https://forums.phpfreaks.com/topic/102551-i-want-tables-for-my-data-by-id/#findComment-525110 Share on other sites More sharing options...
sasa Posted April 23, 2008 Share Posted April 23, 2008 try $result = mysql_query("SELECT * FROM ufm_form_data") or die(mysql_error()); // store the record of the "ufm_form_data" table into $row $current = ''; //echo "<table border='1' width='800'>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { $id = $row['id']; if (!$current) { echo "<table border='1' width='800'>"; $current = $id; } elseif ($current != $id){ echo "</table><table border='1' width='800'>"; $current = $id; } // Print out the contents of each row into a table echo "<tr><th>Company</th><td> {$row['company']}</td><tr>"; echo "<tr><th>FirstName</th><td> {$row['firstName']}</td><tr>"; echo "<tr><th>LastName</th><td> {$row['lastName']}</td><tr>"; echo "<tr><th>Email</th><td> {$row['email']}</td><tr>"; echo "<tr><th>Address</th><td> {$row['address1']}</td><tr>"; echo "<tr><th>City</th><td> {$row['city']}</td><tr>"; echo "<tr><th>State</th><td> {$row['state']}</td><tr>"; echo "<tr><th>Zip Code</th><td> {$row['postalCode']}</td><tr>"; echo "<tr><th>Phone</th><td> {$row['phone']}</td><tr>"; echo "<tr><th>Info</th><td> {$row['info']}</td><tr>"; echo "<tr><th>Quote</th><td> {$row['quote']}</td><tr>"; echo "<tr><th>Comments</th><td> {$row['comments']}</td><tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/102551-i-want-tables-for-my-data-by-id/#findComment-525125 Share on other sites More sharing options...
vetman Posted April 23, 2008 Author Share Posted April 23, 2008 Thank you, if works fine, I just need to put a couple of breaks between the tables. Quote Link to comment https://forums.phpfreaks.com/topic/102551-i-want-tables-for-my-data-by-id/#findComment-525286 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.