[thelist] split() etc
Bill Haenel
mail at webmarketingworx.com
Wed Oct 8 18:34:46 CDT 2003
Might be what you want:
(note - alternatively, instead of an incrementing INT for the array key
on the text fields, substitute meaningful names via another array, do a
foreach instead of a for, and use those keys as row headers when
building the table with the second-to-last foreach)
******************************************************
<html>
<body>
<form method='get' action='<?=$_SERVER['PHP_SELF']?>'>
<?
$n = 3; //set up for number of rows
for ($i=0;$i<$n;$i++) {
?>
<p>enter row data</p>
<textarea name='items[<?=$i?>]'>
<?=$_GET['items'][$i]?>
</textarea>
<?
}
?>
<input type='submit'>
</form>
<p>output</p>:
<?php
if (!empty($_GET['items'])) {
echo '<table border=1>';
foreach($_GET['items'] as $row_num => $row_contents) {
echo '<tr>';
$cells = split(',',$row_contents);
foreach ($cells as $cell) {
echo '<td>'.$cell.'</td>';
}
echo '</tr>';
}
echo "</table>";
}
?>
</body>
</html>
> -----Original Message-----
> From:
> thelist-bounces-mail=webmarketingworx.com at lists.evolt.org
> [mailto:thelist-bounces-mail=webmarketingworx.com at lists.evolt.
> org] On Behalf Of Roger Harness
> Sent: Wednesday, October 08, 2003 16:49
> To: evolt list
> Subject: [thelist] split() etc
>
>
> 'Volters,
>
> i can populate an html table by using a couple of split()
> functions so that if the user types his info separated by
> commas, and then hits a carraige return. the commas separate
> the cells, while the carraige returns separate the table rows.
>
> <form>
> <textarea name='items'></textarea>
> <br /><br />
> <input type='submit'>
> </form>
>
> <table border=1>
> <tr>
> <?php
> make_table($items);
>
> function make_table($txt)
> {
> $textone=split("\r",$txt);
> print "<table border=1>";
> foreach ($textone as $temp)
> {
> $texttwo=split(",",$temp);
> print "<tr>";
> foreach ($texttwo as $temp2)
> {
> print "<td>$temp2</td>";
> }
> print "</tr>";
> }
> print "</table>";
> }
> ?>
>
> AND, i can let the user enter different rows on different text areas:
>
> <html>
> <body>
> <form method='get' action='form_maker3da.php'>enter row
> data<br> <textarea name='items[]'></textarea> <br><br>
> <form>enter row data<br> <textarea name='items[]'></textarea>
> <br /><br /> <input type='submit'> </form> </body> </html>
>
> which goes to:
>
> <html>
> <body>
> <?php
> print "<table border=1>";
> foreach($items as $temp)
> {
> print "<tr>";
> print "<td>$temp</td>";
> print "</tr>";
> }
> print "</table>";
> ?>
> </body>
> </html>
>
> but what I'd *like* to do, is combine these two solutions.
>
> so on the first text area, the user could input dogs, cats,
> birds and on the next text area they could enter horses, worms, fish
>
> so i'm getting each row from a different text area, but its
> still splitting on the commas, instead of the carraige return.
>
> and of course populate a single table with all this exciting
> information.
>
> am i even making sense on here?
>
> as always, tia!
>
> -Roger Harness
>
> --
> * * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/
For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !
More information about the thelist
mailing list