Page 1 of 1

PHP TABLE FORMATTING

Posted: Thu Jun 12, 2003 1:18 pm
by polosport6699
I have been searching for days on the acutal formatting of a MYSQL table in php - to form the html side of it. I want to know how to make a table, give it color, define the column sizes and headings, then put the mysql data in it.

Anyone please help I would be very greatful

Posted: Thu Jun 12, 2003 1:25 pm
by cactus
This should get you started:

http://www.devshed.com/Server_Side/PHP/ ... print_html

Regards,

Helllp

Posted: Thu Jun 12, 2003 2:01 pm
by polosport6699
I dont think you know exactly what im asking.

I want to learn about the end result of the table shown on say
Monster.com. How do I format my tables with php to make them look like that, with colors and pre-definied sizes.

I know how to make a table in mysql and to edit and change values within that but I do not know how to Display the table in php colorfully with images and also predefined column sizes...?

Any help would be quite nice :-)

Posted: Thu Jun 12, 2003 2:07 pm
by caseymanus
what you are asking about is really basic html...not PHP. There are alot of really good tutorials out there on how to write html.

Posted: Thu Jun 12, 2003 2:23 pm
by polosport6699
Aaarg. I KNOW HTML VERY WELL. WHAT I DONT KNOW IS HOW TO FORMAT THE TABLES FOR MYSQL DATA. I KNOW <TABLE></TABLE> CELLSPACING ECT. HOW DO I GET MYSQL TBL DATA INTO IT. I am just learning php

Im talking about formatting of tables using the print function[/b[

Like so

print "<TABLE BORDER=\"0\" align=\"center\" width=\"480\"><TR bgcolor=\"5C83D3\">\n";
print "\t<td><input name=\"check\" type=\"checkbox\" value=\"check\"></td>\n";
foreach ($line as $col_value) {
print "\t<td>$col_value</td>\n";

}
print "\t</tr>\n";

}
print "</table>\n";

I do not know anything about that, if someone could help me with THAT type of table formatting I would be gracious

Posted: Thu Jun 12, 2003 3:26 pm
by twigletmac
First off, you don't format tables using the print() function - you use HTML to format tables. print() does nothing other than output the HTML to the browser - it does not manipulate it.

How far have you got with your database extraction code? Could we see what you have so far?

Mac

Posted: Thu Jun 12, 2003 5:36 pm
by zoki
yo
maybe something like this:

Code: Select all

<table border="1" width="100%">
<tr bgcolor="yellow" align="center"><td><b>First name</b></td><td><b>Last nameb></td></tr>
<?php
$result=mysql_query("select * from addressbook", $db) or die(mysql_error());
while ($myrow=mysql_fetch_row($result)) {
echo "<tr><td>$myrow[0]</td><td>$myrow[1]</td></tr>";
}
?>
</table>
hope that helps a little bit.

Posted: Thu Jun 12, 2003 5:54 pm
by McGruff
zoki wrote:

Code: Select all

<?php
echo "<tr><td>$myrow[0]</td><td>$myrow[1]</td></tr>";
?>

Code: Select all

<?php
// you don't always have to concatenate but it helps:
echo '<tr><td>' . $myrow[0] . '</td><td>' . $myrow[1] . '</td></tr>';
?>
Personally, I don't like html in the code if I can avoid it and always do something like this:

Code: Select all

<?php

// declare vars

include('path_to/template.htm');
?>
Build tables as normal then add the vars in cells with:

Code: Select all

<?php echo $var1; ?> etc
This keeps the formatting separate from the code. Use your html editor to apply styles etc.

Posted: Thu Jun 12, 2003 7:08 pm
by Dak
Maybe you're talking about loops?