Google Answers Logo
View Question
 
Q: php script ( No Answer,   0 Comments )
Question  
Subject: php script
Category: Computers > Programming
Asked by: mgh-ga
List Price: $30.00
Posted: 22 Jun 2004 19:01 PDT
Expires: 27 Jun 2004 12:31 PDT
Question ID: 364829
I have a working script that displays selected records for possible updating.

Where I need help is placing the array data produced by the form script
back into the mysql table on a separate results page.  I'm a bit new at php arrays.

This is a portion results shown on screen from a test script
<?php print "Posted variables: <br>"; ?> from my form results page.
[nhqty_59] => 1 [hqty_59] => 2  [nhqty_79] => 1 [hqty_79] => 2
[nhqty_110] => 1 [hqty_110] => 2,
This data is complete and correct.

Below is a portion of my form script:
<?php
//above here is top of script-> includes for db connection , login etc.
echo"<FORM METHOD=post  < action='updated_june22_1.php' >";
echo"<tr><td>"; // BEGIN ROW For Table-Form (displays the form)
echo"<table width =700 border=0 cellspacing=0   bgcolor=black > "; //
Start table-form
echo"<tr bgcolor=6A5ACD cellspacing=1 ><td colspan= 9 align=center><EM
><b>TEAM &nbsp;&nbsp; $formteamnumber &nbsp;&nbsp; ENTRIES
&nbsp;&nbsp; FOR &nbsp;&nbsp;  WEEK &nbsp;&nbsp;
$formweeknumber</b></EM></td></tr>";
echo"<tr bgcolor=6A5ACD cellspacing=1  ><td><font color =
white>EDIT?</font></td><td><font color = white># of
NH</font></td><td><font color = white># of H</font></td><td><font
color = white># of HP</font></td><td><font color = white># of <br
/>Auto fills</font></td><td><font color = white>Water <br
/>Rentals</font></td><td><nobr><font color = white>Branch
Name</nobr></font></td><td><font color = white><nobr>Date
Entered</nobr></font></td></tr>";
$query = ("SELECT nhqty, hqty, hpqty,afqty
,wrqty,ID,dateentered,branch  FROM order_line2 WHERE
teamnumber=$formteamnumber AND unix_ts BETWEEN $minupdate AND
$maxupdate");echo mysql_error();
$result = mysql_query($query) or die("Select Failed FROM ncl_div4 !"); 
while($row = mysql_fetch_array($result))	   //	 array
{
?>
<tr bgcolor="66CDAA"><td colspan=9 ><br /></td></tr> <!-- BLANK ROW -->
<tr   bgcolor= "66CDAA">
<td >   <!-- Display checkbox column -->
<input type=checkbox class="myselect1" name="<?php echo $row["ID"];
?>" value=<?php echo $row["ID"]; ?>>
</td>
<td >	   <!-- Display dropbox column nhqty["ID"]-->
<select name="nhqty[<?php echo $row["ID"]; ?>" class="myselect1">
<?php
$row["nhqty"] > 20 ? $qt=$row["nhqty"] : $qt=20;   // Added to try to
make the below new or statement work
for($i = 0; $i <= $qt ; $i++)							//		this worked for($i = 0; $i <=
$row["wrqty"] ; $i++)
{ 
echo "<option ";
if($row["nhqty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</td>
<td >	   <!-- Display dropbox column hqty-->
<select name="hqty[<?php echo $row["ID"]; ?>" class="myselect1">
<?php
$row["hqty"] > 20  ? $qt=$row["hqty"] : $qt=20;   // Added to try to
make the below new or statement work
for($i = 0; $i <= $qt ; $i++)							//		this worked for($i = 0; $i <=
$row["wrqty"] ; $i++)
{ 
echo "<option ";
if($row["hqty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</td>
<td >	   <!-- Display dropbox column hpqty-->
<select name="<?php echo $row["hpqty"]; ?>" class="myselect1">
<?php
$row["hpqty"] > 20  ? $qt=$row["hpqty"] : $qt=20;   // Added to try to
make the below new or statement work
for($i = 0; $i <= $qt ; $i++)							//		this worked for($i = 0; $i <=
$row["wrqty"] ; $i++)
{ 
echo "<option ";
if($row["hpqty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</td>
<td >	   <!-- Display dropbox column afqty-->
<select name="<?php echo $row["afqty"]; ?>" class="myselect1">
<?php
$row["afqty"] > 20 ? $qt=$row["afqty"] : $qt=20;   // Added to try to
make the below new or statement work
for($i = 0; $i <= $qt ; $i++)							//		this worked for($i = 0; $i <=
$row["wrqty"] ; $i++)
{ 
echo "<option ";
if($row["afqty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</td>
   //--- More drop down boxes for other fields --- 

<INPUT TYPE=Submit VALUE=Submit>
</form>;

Any help will be appreciated.

Request for Question Clarification by wildeeo-ga on 23 Jun 2004 07:57 PDT
Hi,

Is the 'nhqty' variable you fetch from the database always zero? If
the 'for' loops worked for the 'wrqty' variable, it indicates that the
'nhqty' variable is zero in the database.

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

Clarification of Question by mgh-ga on 27 Jun 2004 12:30 PDT
June 27 ; I got the script working myself, thankyou.

I used 				
<select name="nhqty[]" > for the dropbox name and
and added two hidden fields, 
<input type="hidden" name="ID[]" value=<?=$row["ID"]?>.
All this information is used in an update statement.

The End.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy