Blog 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
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Blog formatting

Post by slippyaah »

just wandered if anyone could help with this slight problem...

When using the following code in my html page for some reason the title bar and title end up at the bottom of the table and the spread of the table is not fully 100%:

$html .= "<table><tr><td colspan=\"100%\" bgcolor=\"#D2D2D2\">";
$html .= "<b>".$line['title']."</b></td></tr><br>";
$html .= "<i><b>".$line['date']." // </b></i>";
$html .= "<i><b>".$line['time']."</b></i><br><br>";
$html .= "".$line['message']."<br><br>";
$html .= "<i><b>".$line['name']."</b></i><br>";
$html .= "</table>";
$html .= "<hr>";
$counter++;


can anyone help me out on what to change to get the title and title bar to the top and get it to spread 100% of the across the page?

thanks

Ian
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

That HTML is pretty FUBARed, you're missing table row and cell tags for the second row and some closing i and b tags as well as using colspan in a manner to which it is not accustomed (you need a width attribute in the table tag to make the table 100% wide).

It's much easier to break out of PHP and then write your HTML or to use heredoc, instead of having a separate echo for each line, therein lies way too much effort and difficulty debugging.

Using heredoc you could have:

Code: Select all

$html =<<<END

<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
	<th bgcolor="#D2D2D2">{$line['title']}</th>
</tr>
<tr>
	<td>
		<p><i><b>{$line['date']} {$line['time']}</b></i></p>
		<p>{$line['message']}</p>
		<p><i><b>{$line['name']}</b></i></p>
	</td>
</tr>
</table>

<hr />
END;
Mac
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Post by slippyaah »

thanks for the tips but I haven't been fully able to implement it into my exisitng code without multiple errors coming up. I'm really new to PHP and don't know enough to debug it all. Shall I send on the page I'm working with?

thanks

Ian
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

show us your entire code.

Don't forget to use [syntax=php][/syntax] around your code so it makes it easier to read for us.

Mark
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Post by slippyaah »

ok here's the entire PHP code within a cell of a html table in my page:

<td width="493" class="mainText"><?php
$link = mysql_connect("localhost", "", "");
mysql_select_db("weblog") or die(" Could not select database");
$sql = "SELECT * FROM entries";
$result = mysql_query($sql) or die("Error getting data");
$html = "";
$counter = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
if ($counter > 0) {
continue;
} else {
$html
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<th bgcolor="#D2D2D2">{$line['title']}</th>
</tr>
<tr>
<td>
<p><i><b>{$line['date']} {$line['time']}</b></i></p>
<p>{$line['message']}</p>
<p><i><b>{$line['name']}</b></i></p>
</td>
</tr>
</table>
<hr />
END;
$counter++;
}
}
$counter = 0;
}
echo $html;
?>
</td>
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Post by slippyaah »

doh, wrong code. The CORRECT full code is:

<td width="493" class="mainText"><?php
$link = mysql_connect("localhost", "", "");
mysql_select_db("weblog") or die(" Could not select database");
$sql = "SELECT * FROM entries";
$result = mysql_query($sql) or die("Error getting data");
$html = "";
$counter = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
if ($counter > 0) {
continue;
} else {
$html .= "<table><tr><td colspan=\"100%\" bgcolor=\"#D2D2D2\">";
$html .= "<b>".$line['title']."</b></td></tr><br>";
$html .= "<i><b>".$line['date']." // </b></i>";
$html .= "<i><b>".$line['time']."</b></i><br><br>";
$html .= "".$line['message']."<br><br>";
$html .= "<i><b>".$line['name']."</b></i><br>";
$html .= "</table>";
$html .= "<hr>";
$counter++;
}
}
$counter = 0;
}
echo $html;
?>
</td>
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Post by slippyaah »

any help would still be greatly appreciated...

Slippy
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you read the info on heredoc I linked to - it can be tricky to start with. Also when you get error messages post them so that we can help you sort them out.

Since this is primarily an HTML problem, check the source of the page created using your code and compare the HTML for the table to the HTML I posted. You need to add in TR and TD tags for the second row and do a little more rejigging.

Mac
Post Reply