PHP TABLE FORMATTING

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
polosport6699
Forum Commoner
Posts: 35
Joined: Wed Jun 11, 2003 3:19 pm

PHP TABLE FORMATTING

Post 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
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

This should get you started:

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

Regards,
polosport6699
Forum Commoner
Posts: 35
Joined: Wed Jun 11, 2003 3:19 pm

Helllp

Post 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 :-)
User avatar
caseymanus
Forum Commoner
Posts: 34
Joined: Wed Nov 20, 2002 10:32 pm
Contact:

Post 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.
polosport6699
Forum Commoner
Posts: 35
Joined: Wed Jun 11, 2003 3:19 pm

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
zoki
Forum Newbie
Posts: 9
Joined: Tue Apr 23, 2002 3:09 pm
Location: Serbia
Contact:

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Last edited by McGruff on Thu Aug 11, 2005 6:01 am, edited 1 time in total.
Dak
Forum Newbie
Posts: 11
Joined: Thu Jun 12, 2003 7:05 pm

Post by Dak »

Maybe you're talking about loops?
Post Reply