Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using PHP for my repeating tables
Old 01-14-2009, 05:19 AM Using PHP for my repeating tables
Average Talker

Posts: 19
Trades: 0
Is there a way for me to stop typing the same html table code for my contents by using PHP? For example

<table border... blah blah cellspacing=1 blah blah>
<tr>
<td valign blah blah>

content content content
</td>
</tr>
</table>


<table border... blah blah cellspacing=1 blah blah>
<tr>
<td valign blah blah>

content content content
</td>
</tr>
</table>


I don't want to keep typing out the bold part of my page for every single content that is in the table, which is required to be. I have about 10 - 15 of these tables on one page, each with its own background image in the cell, is there a way to make it so i dont have to type it out every single time i want to add a new table with its own background?

PS - I'm still very very new to php coding so cut me some slack, thanks.
rogerchin85 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-14-2009, 05:28 AM Re: Using PHP for my repeating tables
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
1. Drop tables. Use divs and css.
2. see http://php.net/foreach
3. Use a local php/apache server to try simple code bits so you see what works and what doesn't and therefore learn the language you're trying to program in
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-14-2009, 06:44 PM Re: Using PHP for my repeating tables
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
One really simple way to do it is like so

PHP Code:
<?php
$content 
= array(
"Content of first table",
"Content of second table",
"Content of third table",
"etc."
);

foreach ( 
$content as $table_content ){
?>
<table border... blah blah cellspacing=1 blah blah>
<tr>
<td valign blah blah>
<?php
echo $table_content;
?>
</td>
</tr>
</table>
<?php
}
?>
Doing it with Divs would definitely be better, though the process here is about the same.
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to Using PHP for my repeating tables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11597 seconds with 12 queries