Jump to content

tables and PHP


andy_b_1502

Recommended Posts

hi everyone,

 

Whats the best way to put my displayed php into my table?

 

I already have gotten to the point where it is displayed, but it looks basic, so i want it to look like the table below it.... i just havent quite figured out how to "space" the data out so it looks better?

 

Is it just a case of printing out what i want where in the table? or is it something more complex?

 

http://www.removalspace.com/indextwo.php

Link to comment
Share on other sites

but thats what i've got in the table below. it's how i want it to look, im just stuck on how to get little individual snippets of the mySQL table to fit it snug where i want it??

 

do you connect to the database first at the top of the page and then call it below in different places how?

 

my code currently looks like this:

 

<?php 
$database="my_db"; 
mysql_connect ("host/server", "user", "password"); 
@mysql_select_db($database) or die( "Unable to select database"); 
$result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) 
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result); 
print "There are $num_rows records.<P>"; 
print "<table width=200 border=1>\n"; 
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n"; 
foreach ($get_info as $field) 
print "\t<td><font face=arial size=1/>$field</font></td>\n"; 
print "</tr>\n"; 
} 
print "</table>\n"; 
?> 

 

that works a treat with the "basic" un-styled table without CSS. but where i think i'm getting confused is it's fetching all the data in one go?

 

 

 

it needs to fit inside this table markup:

 

<table width="1083" height="313" border="2" cellpadding="1" cellspacing="2" bordercolor="#0066FF">
<tr>
					    <td> </td>
					    <td> </td>
					    <td> </td>
					    <td> </td>
					    <td> </td>
					    <td> </td>
				      </tr>

 

 

 

 

 

 

Sooooo i'm guessing it should look something like this:

 

<?php 
$database="my_db"; 
mysql_connect ("host/server", "user", "password"); 
@mysql_select_db($database) or die( "Unable to select database"); 
$result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) 
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result);
<tr>
					    <td>while ($get_info = mysql_fetch_row($result)){</td>
					    <td>foreach ($get_info as $field)</td>
					    <td>this is where i'm getting bogged down?</td>
					    <td> </td>
					    <td> </td>
					    <td> </td>
</tr>

 

 

Link to comment
Share on other sites

Or is this a better way:

 

 

<?php
$database="my_db"; 
mysql_connect ("host/server", "user", "password"); 
@mysql_select_db($database) or 
die( "Unable to select database");
$results = mysql_query($sql); 
while ($row = mysql_fetch_array($results)) {  
print '<tr>';  
print '<td>' . htmlentities($row['col1'] . '</td>';  
print '<td>' . htmlentities($row['col2'] . '</td>';  
print '</tr>'; }
?> 

 

 

Link to comment
Share on other sites

echo '<table width="1083" height="313" border="2" cellpadding="1" cellspacing="2" bordercolor="#0066FF">';
$result = mysql_query ("Select whatever data from whatever table");
while ($row = mysql_fetch_array($result)){
    echo "<tr>"; // PHP loops through each row from the database and draws an HTML table row for each one.
    echo "<td>{$row['field1']}</td>";
    echo "<td>{$row['field2']}</td>";
    echo "<td>{$row['field3']}</td>";
    echo "</tr>"; // End of this table row.
}
echo '</table>'; //We have now looped through each row, so we close the table and we're done.

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.