Jump to content

tables


andy_b_1502

Recommended Posts

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>";
} 

?> 

 

 

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.