On sze, 2007-01-17 at 15:23 +0200, William Stokes wrote:
> Hello,
> 
> I have a script which retrieves rows from DB and prints them to a user 
> editable form to a web page. I don't know how to print the form objects so 
> that all editable fields are put to arrays for updating them to DB. I have 
> tried to create arrays sarjanID[] etc. but havent got it to work...
> 
> Pls. see code below.
> 
> Thanks
> -Will
> 
> $sql = "SELECT * FROM x_kilpailu WHERE omistaja = '$updateid' ORDER BY 
> 'sorter' ASC";
> $row = mysql_fetch_row($result);
> $result = mysql_query($sql);
> $num = mysql_num_rows($result);
> $cur = 1;
> while ($num >= $cur) {

why don't you use this:

while ($row = mysql_fetch_array($result)) {

and then you can omit $cur, and also you won't need $num

>    $row = mysql_fetch_array($result);
>    $id = $row["id"];
>    $nimi = $row["nimi"];
>    $kilpailutyyppi = $row["kilpailutyyppi"];
>    $sarjataulukko = $row["sarjataulukko"];
>    $joukkueitakpl = $row["joukkueitakpl"];
>    $sorter = $row["sorter"];
>    $kilpailut[] = array("$id", "$nimi", "$kilpailutyyppi", "$sarjataulukko", 
> "$joukkueitakpl", "$sorter");  //create arrays here
>    $cur++;
> }
> 
> ......
> 
> foreach ($kilpailut as $value) { //print arrays to a web form
>    if ($value[3] == 1) {
>   $staulu = "Kyll";
>  } elseif ($value[3] == 0) {
>   $staulu = "Ei";
>  }
> 
>  print "<input type=\"hidden\" name=\"sarjanID[ID]\" value 
> =\"$value[0]\">\n";
>  print "<input type=\"text\" name=\"sarjanID[nimi]\" size=\"20\" 
> maxlength=\"20\" value =\"$value[1]\">\n";
>  print "<select name=\"sarjanID[tyyppi]\">\n";
>  print "<option selected>$value[2]</option>\n";
>  print "<option>Sarja</option>\n";
>  print "<option>Cup</option>\n";
>  print "</select>\n";
>  print "<select name=\"sarjanID[sarjataulukko]\">\n";
>  print "<option selected>$staulu</option>\n";
>  print "<option>Kylla;</option>\n";
>  print "<option>Ei</option>\n";
>  print "</select>\n";
>  print "<select name=\"sarjanID[joukkueitayht]\">\n";
>  print "<option selected>$value[4]</option>\n";
>      for ($i=3; $i<=20; $i++ ) {
>     print "<option>$i</option>\n";
>     }
>  print "</select>\n";
>  print "<input type=\"text\" name=\"sarjanID[sortteri]\" value 
> =\"$value[5]\">\n";
>  print "<input type=\"checkbox\" name=\"poista\">Poista kilpailu<br><br>\n";
> } 
> 

all input fields go to $_POST/$_GET depending on the form method you
use. so you don't have to create an array in the form itself.
just do it like

<select name=\"tyyppi\">

and then you will have that value in $_POST['tyyppi'] or $_GET['tyyppi']

greets
Zoltán Németh

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to