Ezilon.com - Target Your Audience, be Seen in Your Region

display results into tables

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 18 posts

Joined: Feb 2005

Ive read somewhere about this result, but I cannot find it again.

My script queries a data file, and displays one after the other until all results are shown. The results can be veried up to many hundreds showing.

How to divide the results into seperate 4 rows evenly as possible?

My script so far:

<?php
list($first) = explode('/', substr($PATH_INFO,1));
$num_results=1000;
$lines = file('/AAACars.data');
$num=count($lines);
$count=0;
foreach (
$lines as $line) {
$parts = explode('|', $line);
if (
$parts[2] == $first) {
$count++;
if(
$count<=$num_results)

echo "<a href=\"/rars.$parts[0].html/$parts[0]/$parts[2]\">$parts[1]</a>";

}}
?>

Busy's picture
Modrater

He has: 6,157 posts

Joined: May 2001

just add echo ""; above the other echo and echo ""; after it, although this would create 1000 table cells :eek: so depending on how many you wanted across you could do another $count_td so if $count_td == amount wide echo a which will create columns.
Thats the easy way, if you wanted it listed downwards in one column then again in another column beside it you have to use a nested table and a bit of math. get the result, divide by two and then echo the end of the nested table then the of the main table then the begining of the second nested table until you get to the end then finish off the tables.

<?bhb if(broken){ echo("It wasn't me Smiling "); } ?>
Learn HTML the ez way - EzHTML.net

Some people are like slinkies, they dont really serve any purpose but they still bring a smile to your face when you push them down the stairs ...

CptAwesome's picture
Sponsor

He has: 370 posts

Joined: Dec 2004

if(is_int($count_td / 4))
{
echo "\n";
}

They have: 18 posts

Joined: Feb 2005

Thanks for the replies,
So far my script does the actions but is abit backwards.
I do need the results side by side, about 4 columns wide/ ?deep.

$NUMBER_OF_ROWS = 4; // number
$lines = file('/rars.data');
$num = count($lines);
$num_cols = ceil($num/$NUMBER_OF_ROWS);
echo '';
for($row = 0; $row < $NUMBER_OF_ROWS; $row++){
echo '';
for($col = 0; $col < $num_cols; $col++){
$n = $num_cols*$row + $col;
if($num <= $n){
$result = ' ';
} else {
$parts = explode('|', $lines[$n]);
$result = ''.$parts[1].'';
}
echo ''.$result.'';
}
echo '';
}
echo '';

However, my script is not displaying the right structure or results.

1. It is not using the URL explode and search function to get my results.
list($first) = explode('/', substr($PATH_INFO,1));
if ($parts[2] == $first) {

ex. http://url.com/orders.php/Paid
Paid in the URL is "$first"
Paid is also "$parts[2]"

2. All my results are showing one-after-the-other across, making the page to wide.

Any help on this matters is surely appreciated.

CptAwesome's picture
Sponsor

He has: 370 posts

Joined: Dec 2004

Well, this actually made me find out something interesting. Ceil and Round convert values to float, and you have to use intval to convert them back to intergers:

<?
$NUMBER_OF_ROWS = 4; // number
$num = count($what_to_count);
$n = 0;
$num_cols = intval(ceil($num/$NUMBER_OF_ROWS));
echo $num_cols;
echo '<table border="1">';
while($n < $num)
{
$i = ($n/$num_cols) * 1;
$j = (($n+1)/$num_cols) * 1;
if(is_int($i)){
echo "<tr><td>";
}else{
echo "<td>";
}
echo "Data ($n)";
if(is_int(($j)/$num_cols)){
echo "</td></tr>";
}else{
echo "</td>";
}
echo "\n";
$n++;
}
?>

'

<? echo implode('',explode('|','A|W|E|S|O|M|E')); ?>

http://www.free-online-web-tools.com

naoshad's picture

He has: 23 posts

Joined: Feb 2005

I think you should use a while loop!

They have: 8 posts

Joined: Feb 2005

<?php
define
("NUM_COLS\", 4);

echo \"<table border='1'> \n\";

$col = 1;
foreach ($items as $item) {
    if ($col == 1) echo \"\t<tr>\";

    echo \" <td>$item</td> \";

    if (++$col == 4) { echo \"</tr>\n\"; $col = 1; }
}

echo \"</table> \n\";
?>