|
Posted by Auddog on 02/07/07 19:13
Rik,
Thanks for the feed back and here is what I got from it. By placing the [ ]
around the $id (what's the periods for???) it will create an array for
$hours. What is the key? I see you assign the id as it's value, is that
html or php? Lastly, when I execute the code all I get on the screen is
Array ( ). I can place all my code here if it would help. Thanks again for
all your help, it is greatly appreciated.
A
Sorry for all the questions, but I want to understand what each line is
doing so that I can get this figured out.
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.tnd3qmlwqnv3q9@misant.kabel.utwente.nl...
Auddog <will_k@hotmail.com> wrote:
> My form is created by querying my database for id, fname, lname of
> employees
> and then I add an input box for hours worked. I want everyone that works
> on
> the production lines listed. I then would like to be able to insert the
> form information into a database. I just don't know how to do this. I'm
> grasping at straws right now.
>
> Here is my form code:
> <?php
>
> // see if any rows were returned
> if (mysqli_fetch_array($result) > 0) {
This would mean you always discard the first row, use
mysqli_num_rows($result) instead.
> while (list($id, $fname, $lname) = mysqli_fetch_row($result))
> {
> echo " <tr>
> <td><input name=$id-hours type=text size=4 maxlength=4 />
> </tr>";
> }
> echo "</table>";
> }
I'd do this:
echo '<input name="hours['.$id.']" type="text" size="4" maxlength="4" >';
And upon receiving, you'll have an array in $_POST (or $_GET, but don't do
that) named 'hours' containing the id as key and the value as the input.
Check this with print_r($_POST['hours']);
To keep using the current form, you'd have to do something like this:
$hours = array();
foreach($_POST as $key => $value){
if(preg_match('/^[0-9]+-hours$/i',$key){
$keyarray = explode('-',$key);
$hours[$keyarray[0]] = $value;
}
}
print_r($hours);
--
Rik Wasmus
Navigation:
[Reply to this message]
|