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
Blog formatting
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
Mac
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;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>
<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>
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>
<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>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
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