Page 1 of 1
problem with table size [only occurs when echoed in php]
Posted: Thu Apr 17, 2003 11:06 am
by legaxy
I'm making a news system on my site, so I made up a html-table which has a set width of 450px, so I have it like this
Code: Select all
<?php
fetch_rows(......)
echo " table info... $rows[1]... $rows[2] etc";
?>
all works fine, the first entry appears and it should but then the second one ignores the size rules and spans the whole page. The second entry (test scenario) is a lot bigger, but still it should obey the width rule right?
any help would be great!
Posted: Thu Apr 17, 2003 11:11 am
by twigletmac
Could we see your actual code? It'll help us determine where the problem might be.
Mac
Posted: Thu Apr 17, 2003 10:23 pm
by legaxy
Code: Select all
<?php
<?
$connect = mysql_connect("*****", "*****", "")
or die("Error! Could not connect: " . mysql_error());
$db = mysql_select_db("venturer" , $connect);
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 5";
$result = mysql_query($query);
while ($rows = mysql_fetch_row ($result)) {
echo (" <table width="449" border="0" align="center" cellpadding="5" cellspacing="0" class="news"><tr><td valign="top"><p><span class="newstitle"> $rows[5] </span><span class="newstop"> <br>posted by <a href="index.php?page=profiles&profile=$row[3]" class="link">$rows[3]</a> on $rows[1]</span><blockquote class="bodytext"><p class="newstext">$rows[6]</p></blockquote></td></tr></table><p> </p> ");
};
?>
?>
it returns the first entry correctly, but the second one goes across the whole page.

Posted: Fri Apr 18, 2003 4:49 am
by m3mn0n
does class="news" have it's own width definition?
Posted: Fri Apr 18, 2003 5:24 am
by twigletmac
What might be easiest is if you have a some formatting in the HTML, try something like:
Code: Select all
<?php
$connect = mysql_connect("*****", "*****", "")
or die("Error! Could not connect: " . mysql_error());
$db = mysql_select_db("venturer" , $connect);
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 5";
$result = mysql_query($query);
// it's generally better to use mysql_fetch_assoc() because then you can reference
// things like $row['column_name'] and don't have to worry if a column is deleted
// or a new one added in the middle messing up all the numbering
while ($rows = mysql_fetch_row($result)) {
// splitting out the echo statements using something like heredoc format can make
// it a lot easier to debug your HTML
// NB. With here doc (the <<<END ... END; stuff) you have to make sure that there are
// no spaces, characters, or tabs before or after END; or after <<<END otherwise you
// get errors
// Bonus of here doc - don't have to escape any quotes
echo <<<END
<table width="449" border="0" align="center" cellpadding="5" cellspacing="0" class="news">
<tr>
<td valign="top">
<p><span class="newstitle">{$rows[5]}</span><br />
<span class="newstop">posted by <a href="index.php?page=profiles&profile={$row[3]}" class="link">{$rows[3]}</a> on {$rows[1]}</span></p>
<blockquote class="bodytext"><p class="newstext">{$rows[6]}</p></blockquote>
</td>
</tr>
</table>
<br />
END;
};
?>
(and take heed of the comments)
Then check the source of the page when it's loaded to see what it says. Also perhaps as Oromian suggested, you may have some width definitions in your CSS - could we see the CSS class information that you're using within the table?
Mac
Posted: Fri Apr 18, 2003 5:26 am
by volka
there's a </p> missing in your code.
using this style
Code: Select all
<?php
$connect = mysql_connect("*****", "*****", "")
or die("Error! Could not connect: " . mysql_error());
$db = mysql_select_db("venturer" , $connect);
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 5";
$result = mysql_query($query);
while ($rows = mysql_fetch_row ($result))
{
?>
<table width="449" border="0" align="center" cellpadding="5" cellspacing="0" class="news">
<tr>
<td valign="top">
<p>
<span class="newstitle"><?php echo $rows[5]; ?></span>
<span class="newstop">
<br />
posted by
<a href="index.php?page=profiles&profile=<?php echo $row[3];?>" class="link">
<?php echo $rows[3]; ?>
</a>
on <?php echo $rows[1];?>
</span>
<blockquote class="bodytext">
<p class="newstext">
<?php echo $rows[6]; ?>
</p>
</blockquote>
</p><!-- added -->
</td>
</tr>
</table>
<p> </p>
<?php
}
?>
it's much easier to find such errors there.
It's untested, so I don't know wether this fixes your problem.
btw: a table with only one cell... is it really necessary?
Posted: Fri Apr 18, 2003 5:33 am
by twigletmac
Either way, by using heredoc (which ok can be painful sometimes but I like it) or by exiting out of the PHP to do the HTML, should help you see your HTML properly formatted instead of all on one line (which is a real pain).
Mac
Posted: Fri Apr 18, 2003 5:37 am
by volka
and another note: you're sure none of your $row-elements contains something that might break down your html-structure?
Code: Select all
<?php
$connect = mysql_connect("*****", "*****", "")
or die("Error! Could not connect: " . mysql_error());
$db = mysql_select_db("venturer" , $connect);
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 5";
$result = mysql_query($query);
while ($rows = mysql_fetch_row ($result))
{
?>
<table width="449" border="0" align="center" cellpadding="5" cellspacing="0" class="news">
<tr>
<td valign="top">
<p>
<span class="newstitle"><?php echo htmlentities($rows[5]); ?></span>
<span class="newstop">
<br />
posted by
<a href="index.php?page=profiles&profile=<?php echo urlencode($row[3]);?>" class="link">
<?php echo htmlentities($rows[3]); ?>
</a>
on <?php echo htmlentities($rows[1]);?>
</span>
<blockquote class="bodytext">
<p class="newstext">
<?php echo htmlentities($rows[6]); ?>
</p>
</blockquote>
</p>
</td>
</tr>
</table>
<p> </p>
<?php
}
?>
Posted: Sat Apr 19, 2003 4:35 am
by legaxy
hey, fixed it, ... i tried putting it all in the way twigletmac suggested, didnt improve it but I emptied the table and put some more posts in, and its fixed itself up now, not too sure wat the problem was, must have been the contents of those posts, the large one had some line breaks in them, so that might have led to it.
thanks all!