Forum Moderators: coopster

Message Too Old, No Replies

So now I have my sorted list of widgets

And I wish I had them printed out in a table.

         

I Will Make It

10:59 am on Feb 27, 2006 (gmt 0)

10+ Year Member



My list is inside a textfile.txt . The textfile look like this:
line1
line2
line3
¦
v
line50

I would like it to be printed out this way inside a table:

line1 - line11
line2 - line12
line3 - line13
line4 - line14
line10 - line21

In words: Split the list for every 10th line, start listing the next 10 lines in a new <td>
do this untill there is no more lines in the list :D

I understand I have to use a loop to count the lines in the textfile.txt, but how do I write it?

omoutop

12:57 pm on Feb 27, 2006 (gmt 0)

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



You can try something like :

[php]

// i assume you have read all the data of the text file
// and got them into an array ($array_data)

$max_records = count($array_data); // max results
$max_cols = 10; // number of columns in table
$max_rows = ceil($max_records/$max_cols); // max rows in table
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?
for ($i=1;$i<=$max_rows;$i++) // creates the rows of table
{
echo "<tr>";
for ($j=1;$j<=$max_cols;$j++) // create colums of table
{
if ($i==1) {$k = ($j+$i)-2;}
else ($k = ($j+$i)+1;)

echo "<td>".$array_data[$k]."</td>"; // value in each colum
} // close for $j
echo "</tr>";
} // close for $i
?>
</table>
[/php]

I Will Make It

1:22 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



mhhm... Thank you!
It's the counters that makes my brain stop ;)

I Will Make It

1:59 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



It worked out almost ok :)

Except that it repeats the values inside the textfile.

I have about 50 lines in the textfile.
these are sorted with:


$widgets = file("textfiles/".$widget."_number.txt");
sort($widgets);

I get multiple results for some of the values..
seems like it repeats 10 values all the time, and the other 40 never get printed..

any idea?