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) {
$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";
}
Here is an example that I just setup on my new billing system
Section/Row1
<div class="col1">Location/Contact Name:</div>
<div class="col2"><input type="hidden"
name="myValues[sec0][location_name']" value="Billing Address" size=32
maxlength=64 autocomplete="off" />Billing Address</div>
<div class="col1">First Name:</div>
<div class="col2"><input type="text" name="myValues[sec0][first_name]"
size=32 maxlength=64 autocomplete="off" /></div>
<div class="col1">Last Name:</div>
<div class="col2"><input type="text" name="myValues[sec0][last_name]"
size=32 maxlength=64 autocomplete="off" /></div>
<div class="col1">Middle Name:</div>
<div class="col2"><input type="text" name="myValues[sec0][middle_name]"
size=32 maxlength=64 autocomplete="off" /></div>
<div class="col1">address 1:</div>
<div class="col2"><input type="text" name="myValues[sec0][address1]"
size=48 maxlength=255 autocomplete="off" /></div>
Section/Row2
<div class="col1">Location/Contact Name:</div>
<div class="col2"><input type="hidden"
name="myValues[sec1][location_name']" value="Ship To" size=32
maxlength=64 autocomplete="off" />Service Location</div>
<div class="col1">First Name:</div>
<div class="col2"><input type="text" name="myValues[sec1][first_name]"
size=32 maxlength=64 autocomplete="off" /></div>
<div class="col1">Last Name:</div>
<div class="col2"><input type="text" name="myValues[sec1][last_name]"
size=32 maxlength=64 autocomplete="off" /></div>
<div class="col1">Middle Name:</div>
<div class="col2"><input type="text" name="myValues[sec1][middle_name]"
size=32 maxlength=64 autocomplete="off" /></div>
<div class="col1">address 1:</div>
<div class="col2"><input type="text" name="myValues[sec1][address1]"
size=48 maxlength=255 autocomplete="off" /></div>
Then on the server side, I do this.
// Sent via POST
if ( isset( $_POST['myValues'] ) ) {
foreach ( $_POST['myValues'] AS $section => $data ) {
// $data is now an array that contains all the entries for the
specific section ie: sec0, sec1, etc...
// Do something with $data
}
} else {
die("didn't get anything");
}
Jim Lucas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php