andy_b_1502 Posted February 17, 2012 Share Posted February 17, 2012 Hi everyone! I am trying to figure out how to put echoed php results from mySQL database into a table ready for styling to look how i want it too. So far i have got to the point where the results are echoed out but they are not in a good table layout. (under "latest removalspace user's) I want it more structured in my table. I have found out how to create the table but just not been able to work out how to fit the echo's in without snytax errors??? the "new" table that i want to use is near the end of the script. <?php // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies") or die(mysql_error()); // store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "Name:\r".$row['company_name']; echo "\r\rLocation:\r".$row['location']; echo "\r\rPostcode:\r".$row['postcode']; echo "\r\nBasic Users:\r".$row['basicpackage_description']; echo "\r\nPremium Users:\r".$row['premiumuser_description']; echo "\r\nlogo:\r".$row['upload']; echo "<img src=\"http://www.removalspace.com/images/COMPANIES" . $row['upload'] . "\" alt=\"logo\" />"; echo "<table> <tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257176-tables/ Share on other sites More sharing options...
Muddy_Funster Posted February 17, 2012 Share Posted February 17, 2012 use echo to build the table and headings before you run the while loop, then during the loop echo the results into the table: echo "<table> <tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; // store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "<tr><td>{$row['company_name']}</td>"; echo "<td>{$row['location']}</td>"; echo "<td>{$row['postcode']}</td>"; echo "<td>{$row['basicpackage_description']}</td>"; echo "<td>{$row['premiumuser_description']}</td>"; echo "<td>{$row['upload']}</td>"; echo "<td><img src=\"http://www.removalspace.com/images/COMPANIES{$row['upload']}\" alt=\"logo\" /></td></tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/257176-tables/#findComment-1318298 Share on other sites More sharing options...
andy_b_1502 Posted February 17, 2012 Author Share Posted February 17, 2012 thanks Muddy! Quote Link to comment https://forums.phpfreaks.com/topic/257176-tables/#findComment-1318305 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.