Clarification of Question by
mgh-ga
on
23 Jun 2004 10:11 PDT
Question: Is the 'nhqty' variable you fetch from the database always zero?
Answer: No, it is not always 0. nhqy is an interger field, generally
containing numbers between 0 and 20, the default for the field is 0.
Perhaps I can clarify some more.
On a TEST RUN using the update form script shown, after selecting week
7 and team #3 in a login form that proceeds this form,
the page with this update form creates came on screen.
As there where only 3 records matching team 3 during the week 7 time
period in the db table, this update form depicted these 3 records in
three html table rows, each row having one checkbox, 4 dropboxes and 2
text areas - the two text areas show the branch name and date of
input.
Going back to the script for a moment and taking the nhqty field by
itself, below is the part of my form update script that creates the
nhyqty dropboxes. 'ID' is an auto incrementing field I'm using to id
the records.
<td > <!-- Display dropbox column nhqty["ID"]-->
<select name="nhqty[<?php echo $row["ID"]; ?>" class="myselect1">
<?php
$row["nhqty"] > 20 ? $qt=$row["nhqty"] : $qt=20;
for($i = 0; $i <= $qt ; $i++)
{
echo "<option ";
if($row["nhqty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
The drop boxes show the current value in the DB and usually have
option values from 0 - 20.
Occationally, the db field may have an existing value higher number
than 20. When that happens, the drop box values shown are that
'higher existing value' through 0.
This statement , $row["nhqty"] > 20 ? $qt=$row["nhqty"] : $qt=20; ,
is for those situations. This seems to work, I had one field with
anexisting value of 549 in it and the drop box shown had option values
from 0 to 549.
Back to my test case, for the 3 records shown, I entered a 5 ,6 and 7
respectively into the three nhqty drop boxes. The existing db values
were 0, 0 and 1.
I then clicked submit and my test result page, with the script <?php
print "Posted variables: <br>"; ?> came up showing, along with my
other form array varibles, these; my three described above drop box
selections;
nhqty_59 = 5
nhqty_79 = 6
nhqty_110 = 7
These seem correct. The 59, 79 and 110 are the correct ID values for
the three records and of course the 5 6 and 7 are the values I
selected in the dropboxes.
Where I seem to need help is getting this data back into the db as an update.
I've seen scripts with mysql update statement inside a foreach loops.
I'm not sure how to sort my array data into an update statement. I've
never seen an underline in the arrays as mine show.
I did try
nhqty<?php echo $row["ID"]; ?>"
instead of
nhqty[<?php echo $row["ID"]; ?>"
and got a array display of
nhqty59 = 5
nhqty79 = 6
nhqty110 = 7
Of course that didn't help me much.
Anyway, I hope that helps clarify things.
Mike