Forum Moderators: coopster

Message Too Old, No Replies

Wrapping php looping output in a table

I want users to scroll down, not to the right

         

chopin2256

2:16 am on Aug 12, 2005 (gmt 0)

10+ Year Member



Ok, I want to "wrap" a looping output in a table. In regular html this is how you can wrap text:

<table width="100%">
<tr>
<td>wrap long line of text here</td>
</tr>
</table>

Can't get this to work in php though. Now I want to embed the php code in this table...here is the code:

echo "<TABLE width="100%"><TR><TD><a href=$INFO[board_url]/composer.php/act/SF/f/$row[fid] class=link7><font size='3'>$row[fname]</font></a> &nbsp;".$row[fdescription];
echo "</TD></TR></TABLE>";

Don't worry about the code really, my main concern is the code performs a loop, but it keeps going across the page causing users to scroll across to the right really far. The looping should theoretically wrap inside the table, but I guess the syntax is wrong. How can I make this code wrap in the table?

coopster

2:27 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You have to be careful when using single quotes and double quotes together. PHP thinks you are ending your string when you hit the next double quotation mark. Try another syntax approach.

echo "<TABLE width=\"100%\"><TR><TD><a href={$INFO['board_url']}/composer.php/act/SF/f/{$row['fid']} class=\"link7\"><font size=\"3\">{$row['fname']}</font></a> &nbsp;".$row[fdescription]; 
echo "</TD></TR></TABLE>";

Some helpful reading:
Strings [php.net]
Arrays [php.net]

chopin2256

3:04 am on Aug 12, 2005 (gmt 0)

10+ Year Member



Thanks,

The problem is still occuring though. Consider this simple piece of code:

<?
echo "<table width = \"100%\"><tr><td>long string</td></tr></table>";
?>

How come this is not wrapping?

grandpa

7:43 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My guess is that your table is expanding to 100% of the data length. You could try imposing a width on the TD element.

<table width = \"100%\"><tr><td width = \"350px\">long string</td></tr></table>

omoutop

8:53 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The best thing to do (I think) is to write the html part in html and the php part inside the php tags so u wont have any problems....simple example in a html form (dynamic drop-down box getting variables from db and looping...)

<form name="form1" method="post" action="Votes-<? echo $Location?>.htm">

<select name="Location" size="1">

<option value="<? echo $Location?>" selected>Please Select</option>

<?

$query = 'select distinct Location from Scores '

."where Flag='A'";

$result = mysql_query($query);

while ($row=mysql_fetch_assoc($result))

{

$Location = $row ['Location'];?>

<option value="<? echo $Location?>"><? echo $Location?></option>
<?
}
?>

<div align=center>

<input type="submit" name="Submit" value="Go!">

</form>

I can not imagine myself writing all this in an echo'';....no way...

chopin2256

6:04 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



Nothing is working. The thing this code does is loop columns according to while/if statements. So I don't think I can do the html part in html. Correct me if I am wrong.

Here is part of the code

--------------------------------------------------

echo "<TABLE width=\"100%\"><TR><TD>";
while($row = $DB->fetch_row($result) and ($counter<$navlimit)) {
if ($row[tdescription]!="") {$tdescription = " [".$row[tdescription]."]";}
else {$tdescription="";};
if ($row[fdescription]!="") {$fdescription = " [".$row[fdescription]."]";}
else {$fdescription="";};

if ($oforumid!= $row[fid]) {
$counter+=1;
echo "</TD><TD width=\"45px\"><a href=$INFO[board_url]/index.php?showuser=$row[fid] class=link7><font size='3'>$row[fname]</a></font> - <a href=$INFO[board_url]/index.php?act=Mail&CODE=00&MID=$row[fid]><font size='2'>(Email)</font></a> &nbsp;".$row[fdescription];

------------------------------------------------------

This table won't wrap...even if I declare a td px size.

chopin2256

6:24 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



Acutally, this isn't a php problem. I just noticed that any long string will not work with the width = %100. The problem is, if there are no spaces, it wont wrap at all, even in plain html. Is there a way to wrap a long line of text if there are no spaces? I am guessing the looping code doesnt output spaces which is why I am getting this problem.

chopin2256

7:51 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



I found the problem. My code is producing infinite columns. Is there a way to set the amount of columns on a page and than wrap those columns?