Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 12th Feb 2011, 12:20 PM   #1
Handsome ... but Humble :
War Room Member
 
Jack Bastide's Avatar
 
Join Date: 2003
Location: , , USA.
Posts: 576
Thanks: 94
Thanked 204 Times in 92 Posts
Default
Printing HTML with PHP
Share on: 
fb share twitter share gplus share more share

Hey Guys,

I have a little PHP program that reads a
database and prints a table of ads

the output look like this

http://freeheadlinecreator.com/jackads.php

the ads are single column like this:

Ad 1
Ad 2
Ad 3
Ad 4
etc

I Want to have two columns like this

Ad 1 Ad 2
Ad 3 Ad 4

This is the code that's printing the ads


while ($Row = mysql_fetch_array($Result))

{

$i=$i+1;


print("<table style=\"border-collapse: collapse\" bgcolor=\"#FFFFFF\" bordercolor=\"#dddddd\" border=\"1\" width=\"250\"

cellpadding=\"0\" cellspacing=\"0\">\n<tr><td bgcolor=\"#330099\"><table border=\"0\" width=\"100%\" >\n<tr><td width=\"1\"><img

border=\"0\" src=\"images/blank.gif\" width=\"1\" height=\"1\"></td>\n<td width=\"100%\" align=\"left\">\n<font color=\"white\"><font

color=\"white\"><b><center> $Row[ad_line1]</b></font></font></center></td><td width=\"50%\"

dir=\"rtl\"></td></tr></table></td></tr><tr><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"7

\"></td></tr><tr><td width=\"14\"></td><td width=\"5\"></td><td valign=\"top\" align=\"center\">$Row[ad_line2]<br>$Row[ad_line3]<br><a

href=\"http://$Row[ad_line4]\" rel="nofollow" target=\"_blank\">$Row[ad_line4]</a><br>\n\n</td><td width=\"14\"></td></tr><tr><td height=\"12

\"></td></tr></table></td></tr></table><br>");

}

Any idea on how i can modify this to be 2 Columns?

Jack

If you can drive Biz Op Phone Calls .... I'm Buying
Jack Bastide is offline  
Unread 12th Feb 2011, 12:40 PM   #2
Peaceful Warrior
War Room Member
 
theIMgeek's Avatar
 
Join Date: 2009
Location: Calgary
Posts: 277
Thanks: 16
Thanked 106 Times in 63 Posts
Default
Re: Printing HTML with PHP
Share on: 
fb share twitter share gplus share more share

The code you posted prints one ad, and repeats four times. I modified it so that it doesn't print directly, but rather stores each ad in the $myAds variable. After it stores all four ads, it displays them in a new table.


$myAds = array();

while ($Row = mysql_fetch_array($Result))

{

$i=$i+1;


$myAds[] = ("<table style=\"border-collapse: collapse\" bgcolor=\"#FFFFFF\" bordercolor=\"#dddddd\" border=\"1\" width=\"250\"

cellpadding=\"0\" cellspacing=\"0\">\n<tr><td bgcolor=\"#330099\"><table border=\"0\" width=\"100%\" >\n<tr><td width=\"1\"><img

border=\"0\" src=\"images/blank.gif\" width=\"1\" height=\"1\"></td>\n<td width=\"100%\" align=\"left\">\n<font color=\"white\"><font

color=\"white\"><b><center> $Row[ad_line1]</b></font></font></center></td><td width=\"50%\"

dir=\"rtl\"></td></tr></table></td></tr><tr><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"7

\"></td></tr><tr><td width=\"14\"></td><td width=\"5\"></td><td valign=\"top\" align=\"center\">$Row[ad_line2]<br>$Row[ad_line3]<br><a

href=\"http://$Row[ad_line4]\" rel="nofollow" target=\"_blank\">$Row[ad_line4]</a><br>\n\n</td><td width=\"14\"></td></tr><tr><td height=\"12

\"></td></tr></table></td></tr></table><br>");

}

print ('<table width="100%">
<tr>
<td width="50%">'.$myAds[0].'</td>
<td width="50%">'.$myAds[1].'</td>
</tr>
<tr>
<td width="50%">'.$myAds[2].'</td>
<td width="50%">'.$myAds[3].'</td>
</tr>
</table>');


-Ryan

FREE WSO: Protect and Automatically Deliver Your Digital Products

Ask the Internet Marketing Geek
<-- Happy to help with technical challenges
MiniSiteMaker.org <-- Free software to make your mini-sites fast and easy
theIMgeek is offline  
Unread 12th Feb 2011, 11:33 PM   #3
PeaceRoom Member
 
webpro4hire's Avatar
 
Join Date: 2011
Location: Montreal, Canada
Posts: 85
Thanks: 12
Thanked 9 Times in 9 Posts
Default
Re: Printing HTML with PHP
Share on: 
fb share twitter share gplus share more share

perhaps the quickest, dirtiest way would be to wrap the output in a DIV, width 520px. Then add a float: left; to each ads' main table. This would force each main table to display to the right of the previous table, which having only enough space for 2 tables (their width=250), would display 2 columns. Increase the DIV width for more columns per row.

However, to do this "right", you would need to refactor the code to allow more flexibility in displaying the results. For one thing, the content should not be printed on each iteration of the while loop. This is the reason you are having this issue with number of "columns", the layout is forced by the loop. A good refactoring would let you program the number of columns.

Another thing, why the table layout??? this could be done wayyyy more efficiently and cleanly using styles.

Also .. $i=$i+1 .. where is this used? should be $i++; or if you need to know the number of rows : mysql_num_rows($Result);

Cheers,
WebPro
webpro4hire is offline  
Closed Thread


Bookmarks

Tags
html, php, printing


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




All times are GMT -6. The time now is 09:08 AM.