to insert data in a html table

This is a discussion on to insert data in a html table within the PHP Language forums, part of the PHP Programming Forums category; Hello, here is the code: <? $a=array(1,2,3,4,5,6,7,8,9,10); $b=array(...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-13-2004
 
Posts: n/a
Default to insert data in a html table

Hello,

here is the code:

<?
$a=array(1,2,3,4,5,6,7,8,9,10);
$b=array(1,3,5,7,9);
$c=array(1,1,2,2,3,3);
$d=array_count_values($b);
$e=array_count_values($c);

foreach($a as $key)
echo '<table><tr><td>'.$key.'</table></tr></td>';

foreach($d as $key=>$value)
echo '<table><tr><td>'.$key.'<td>'.$value.'</table></tr></td>';

foreach($e as $key=>$value)
echo '<table><tr><td>'.$key.'<td>'.$value.'</table></tr></td>';
?>

the result will be :

1
2
3
4
5
6
7
8
9
10
1 1
3 1
5 1
7 1
9 1
1 2
2 2
3 2

how can I formulate a php code to insert all in the same html table, like
this :

1 1 1 1 2
2 3 1 2 2
3 5 1 3 2
4 7 1
5 9 1
6
7
8
9
10

Thank you.


Reply With Quote
  #2 (permalink)  
Old 12-13-2004
Pedro Graca
 
Posts: n/a
Default Re: to insert data in a html table

<a> wrote:
> here is the code:
>
> <?
> $a=array(1,2,3,4,5,6,7,8,9,10);
> $b=array(1,3,5,7,9);
> $c=array(1,1,2,2,3,3);
> $d=array_count_values($b);
> $e=array_count_values($c);


<snip>

> how can I formulate a php code to insert all in the same html table

?


You have to fill each <td>...</td> from different arrays with different
indexes. Tough!


<?php
$a = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$b = array(1, 3, 5, 7, 9);
$c = array(1, 1, 2, 2, 3, 3);
$d = array_count_values($b);
$e = array_count_values($c);

reset($a); reset($d); reset($e);
$aempty = $dempty = $eempty = false;

echo "<table>\n";
while (!$aempty || !$dempty || !$eempty) {
$row = "";

if (list($akey, $aval) = each($a)) $row .= "<td>$aval</td>";
else { $row .= "\x01"; $aempty = true; }

if (list($dkey, $dval) = each($d)) $row .= "<td>$dkey</td><td>$dval</td>";
else { $row .= "\x01\x01"; $dempty = true; }

if (list($ekey, $eval) = each($e)) $row .= "<td>$ekey</td><td>$eval</td>";
else { $row .= "\x01\x01"; $eempty = true; }

if ($row != "\x01\x01\x01\x01\x01") {
echo "<tr>", str_replace("\x01", '<td>--</td>', $row), "</tr>\n";
}
}
echo "</table>\n";
?>

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Reply With Quote
  #3 (permalink)  
Old 12-13-2004
 
Posts: n/a
Default Re: to insert data in a html table

Tank you for the answer !


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:39 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0