Page 1 of 1
Blog formatting
Posted: Wed Jan 14, 2004 5:38 am
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
Posted: Wed Jan 14, 2004 5:51 am
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
Posted: Wed Jan 14, 2004 6:06 am
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
Posted: Wed Jan 14, 2004 6:12 am
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
Posted: Wed Jan 14, 2004 6:19 am
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>
Posted: Wed Jan 14, 2004 6:53 am
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>
Posted: Wed Jan 14, 2004 8:04 am
by slippyaah
any help would still be greatly appreciated...
Slippy
Posted: Wed Jan 14, 2004 8:21 am
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