Updating Multiple Rolls Using PHP

Updating Multiple Rolls Using PHP

am 17.08.2007 16:25:36 von chimambo

Hi All,
I have a little problem. I am retrieving records from a table and I
want to update the records using checkboxes. I am able to display the
database record quite alright and I have created an array of
checkboxes, but my update loop is not working. Here is my code:
/*---------This retrieves the records -------------*/
if($row_md)
{
do{
echo "";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "";
echo "";
echo $row_md['drug_desc'];
echo "";
echo "";
echo $row_md['dose'];
echo "";
echo "";
echo "";
echo "";
}
while($row_md = mysql_fetch_assoc($md));
/*
------------------------------------------------------------ -----------------------------------
*/
/*--------------This should update the records but its not working
----------*/

while (list ($key,$val) = @each ($stop))
{
$mysql_query="UPDATE irdb_temp_medication
SET active = '$val'
WHERE h_number = '$hos_no')";
}

Re: Updating Multiple Rolls Using PHP

am 17.08.2007 16:43:49 von Captain Paralytic

On 17 Aug, 15:25, chima...@googlemail.com wrote:
> Hi All,
> I have a little problem. I am retrieving records from a table and I
> want to update the records using checkboxes. I am able to display the
> database record quite alright and I have created an array of
> checkboxes, but my update loop is not working. Here is my code:
> /*---------This retrieves the records -------------*/
> if($row_md)
> {
> do{
> echo "";
> echo date('d-m-Y', strtotime($row_md['med_date']));
> echo "";
> echo "";
> echo $row_md['drug_desc'];
> echo "";
> echo "";
> echo $row_md['dose'];
> echo "";
> echo "";
> echo "=
";
> echo "";
> }
> while($row_md =3D mysql_fetch_assoc($md));
> /*
> ------------------------------------------------------------ -------------=
--=AD--------------------
> */
> /*--------------This should update the records but its not working
> ----------*/
>
> while (list ($key,$val) =3D @each ($stop))
> {
> $mysql_query=3D"UPDATE irdb_temp_medication
> SET active =3D '$val'
> WHERE h_number =3D '$hos_no')";
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -

How is $stop getting a value?

Re: Updating Multiple Rolls Using PHP

am 17.08.2007 16:58:54 von luiheidsgoeroe

On Fri, 17 Aug 2007 16:25:36 +0200, wrote:

> Hi All,
> I have a little problem. I am retrieving records from a table and I
> want to update the records using checkboxes. I am able to display the
> database record quite alright and I have created an array of
> checkboxes, but my update loop is not working. Here is my code:
> /*---------This retrieves the records -------------*/
> if($row_md)
> {
> do{
> echo "";
> echo date('d-m-Y', strtotime($row_md['med_date']));
> echo "";
> echo "";
> echo $row_md['drug_desc'];
> echo "";
> echo "";
> echo $row_md['dose'];
> echo "";
> echo "";
> echo "";

(assuming a post)

echo " ]}'>";
(or whatever the primary key is called)

> echo "";
> }
> while($row_md =3D mysql_fetch_assoc($md));
> /*
> ------------------------------------------------------------ ----------=
-------------------------
> */
> /*--------------This should update the records but its not working
> ----------*/
>
> while (list ($key,$val) =3D @each ($stop))
> {
> $mysql_query=3D"UPDATE irdb_temp_medication
> SET active =3D '$val'
> WHERE h_number =3D '$hos_no')";
> }

Assumptions:
1. Form is posted.
2. Primary key is h_number
3. h_number is an integer
4. You're trying to set `active` to 'N' (=3Dstop), else it would be 'Y' =
=

(=3Dstart).

if(isset($_POST['stop'])){
$off =3D array_map('intval',$_POST['stop']);
$string =3D implode(',',$off);
mysql_query("UPDATE irdb_temp_medication
SET active =3D 'N'
WHERE `h_number` IN ({$string})");
}


(If not-selected checkboxes should all be set to Y also:)

if(isset($_POST['stop']) && is_array($_POST['stop'])){
$off =3D array_map('intval',$_POST['stop']);
$string =3D implode(',',$off);
mysql_query("UPDATE irdb_temp_medication
SET `active` =3D IF(`h_number` IN ({$string}),'N','Y')");
}
-- =

Rik Wasmus

Re: Updating Multiple Rolls Using PHP

am 23.08.2007 11:07:41 von chimambo

On 17 Aug, 15:58, Rik wrote:
> On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
> > Hi All,
> > I have a little problem. I am retrieving records from a table and I
> > want to update the records using checkboxes. I am able to display the
> > database record quite alright and I have created an array of
> > checkboxes, but my update loop is not working. Here is my code:
> > /*---------This retrieves the records -------------*/
> > if($row_md)
> > {
> > do{
> > echo "";
> > echo date('d-m-Y', strtotime($row_md['med_date']));
> > echo "";
> > echo "";
> > echo $row_md['drug_desc'];
> > echo "";
> > echo "";
> > echo $row_md['dose'];
> > echo "";
> > echo "";
> > echo "";
>
> (assuming a post)
>
> echo " }'>";
> (or whatever the primary key is called)
>
> > echo "";
> > }
> > while($row_md =3D mysql_fetch_assoc($md));
> > /*
> > ------------------------------------------------------------ -----------=
----=AD--------------------
> > */
> > /*--------------This should update the records but its not working
> > ----------*/
>
> > while (list ($key,$val) =3D @each ($stop))
> > {
> > $mysql_query=3D"UPDATE irdb_temp_medication
> > SET active =3D '$val'
> > WHERE h_number =3D '$hos_no')";
> > }
>
> Assumptions:
> 1. Form is posted.
> 2. Primary key is h_number
> 3. h_number is an integer
> 4. You're trying to set `active` to 'N' (=3Dstop), else it would be 'Y' =20
> (=3Dstart).
>
> if(isset($_POST['stop'])){
> $off =3D array_map('intval',$_POST['stop']);
> $string =3D implode(',',$off);
> mysql_query("UPDATE irdb_temp_medication
> SET active =3D 'N'
> WHERE `h_number` IN ({$string})");
>
> }
>
> (If not-selected checkboxes should all be set to Y also:)
>
> if(isset($_POST['stop']) && is_array($_POST['stop'])){
> $off =3D array_map('intval',$_POST['stop']);
> $string =3D implode(',',$off);
> mysql_query("UPDATE irdb_temp_medication
> SET `active` =3D IF(`h_number` IN ({$string}),'N'=
,'Y')");}
>
> --
> Rik Wasmus- Hide quoted text -
>
> - Show quoted text -

Thanks but this code does not retrieve the records for updating. How
do I proceed?

Re: Updating Multiple Rolls Using PHP

am 23.08.2007 12:12:17 von chimambo

On 23 Aug, 10:07, chima...@googlemail.com wrote:
> On 17 Aug, 15:58, Rik wrote:
>
>
>
>
>
> > On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
> > > Hi All,
> > > I have a little problem. I am retrieving records from a table and I
> > > want to update the records using checkboxes. I am able to display the
> > > database record quite alright and I have created an array of
> > > checkboxes, but my update loop is not working. Here is my code:
> > > /*---------This retrieves the records -------------*/
> > > if($row_md)
> > > {
> > > do{
> > > echo "";
> > > echo date('d-m-Y', strtotime($row_md['med_date']));
> > > echo "";
> > > echo "";
> > > echo $row_md['drug_desc'];
> > > echo "";
> > > echo "";
> > > echo $row_md['dose'];
> > > echo "";
> > > echo "";
> > > echo "";
>
> > (assuming a post)
>
> > echo " ']}'>";
> > (or whatever the primary key is called)
>
> > > echo "";
> > > }
> > > while($row_md =3D mysql_fetch_assoc($md));
> > > /*
> > > ------------------------------------------------------------ ---------=
------­­--------------------
> > > */
> > > /*--------------This should update the records but its not working
> > > ----------*/
>
> > > while (list ($key,$val) =3D @each ($stop))
> > > {
> > > $mysql_query=3D"UPDATE irdb_temp_medication
> > > SET active =3D '$val'
> > > WHERE h_number =3D '$hos_no')";
> > > }
>
> > Assumptions:
> > 1. Form is posted.
> > 2. Primary key is h_number
> > 3. h_number is an integer
> > 4. You're trying to set `active` to 'N' (=3Dstop), else it would be 'Y'=
=20
> > (=3Dstart).
>
> > if(isset($_POST['stop'])){
> > $off =3D array_map('intval',$_POST['stop']);
> > $string =3D implode(',',$off);
> > mysql_query("UPDATE irdb_temp_medication
> > SET active =3D 'N'
> > WHERE `h_number` IN ({$string})");
>
> > }
>
> > (If not-selected checkboxes should all be set to Y also:)
>
> > if(isset($_POST['stop']) && is_array($_POST['stop'])){
> > $off =3D array_map('intval',$_POST['stop']);
> > $string =3D implode(',',$off);
> > mysql_query("UPDATE irdb_temp_medication
> > SET `active` =3D IF(`h_number` IN ({$string}),'=
N','Y')");}
>
> > --
> > Rik Wasmus- Hide quoted text -
>
> > - Show quoted text -
>
> Thanks but this code does not retrieve the records for updating. How
> do I proceed?- Hide quoted text -
>
> - Show quoted text -

Ok, its not giving me any error, but its not updating either.

Re: Updating Multiple Rolls Using PHP

am 23.08.2007 17:00:36 von Jerry Stuckle

chimambo@googlemail.com wrote:
> On 23 Aug, 10:07, chima...@googlemail.com wrote:
>> On 17 Aug, 15:58, Rik wrote:
>>
>>
>>
>>
>>
>>> On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
>>>> Hi All,
>>>> I have a little problem. I am retrieving records from a table and I
>>>> want to update the records using checkboxes. I am able to display the
>>>> database record quite alright and I have created an array of
>>>> checkboxes, but my update loop is not working. Here is my code:
>>>> /*---------This retrieves the records -------------*/
>>>> if($row_md)
>>>> {
>>>> do{
>>>> echo "";
>>>> echo date('d-m-Y', strtotime($row_md['med_date']));
>>>> echo "";
>>>> echo "";
>>>> echo $row_md['drug_desc'];
>>>> echo "";
>>>> echo "";
>>>> echo $row_md['dose'];
>>>> echo "";
>>>> echo "";
>>>> echo "";
>>> (assuming a post)
>>> echo "";
>>> (or whatever the primary key is called)
>>>> echo "";
>>>> }
>>>> while($row_md = mysql_fetch_assoc($md));
>>>> /*
>>>> ------------------------------------------------------------ ---------------­­--------------------
>>>> */
>>>> /*--------------This should update the records but its not working
>>>> ----------*/
>>>> while (list ($key,$val) = @each ($stop))
>>>> {
>>>> $mysql_query="UPDATE irdb_temp_medication
>>>> SET active = '$val'
>>>> WHERE h_number = '$hos_no')";
>>>> }
>>> Assumptions:
>>> 1. Form is posted.
>>> 2. Primary key is h_number
>>> 3. h_number is an integer
>>> 4. You're trying to set `active` to 'N' (=stop), else it would be 'Y'
>>> (=start).
>>> if(isset($_POST['stop'])){
>>> $off = array_map('intval',$_POST['stop']);
>>> $string = implode(',',$off);
>>> mysql_query("UPDATE irdb_temp_medication
>>> SET active = 'N'
>>> WHERE `h_number` IN ({$string})");
>>> }
>>> (If not-selected checkboxes should all be set to Y also:)
>>> if(isset($_POST['stop']) && is_array($_POST['stop'])){
>>> $off = array_map('intval',$_POST['stop']);
>>> $string = implode(',',$off);
>>> mysql_query("UPDATE irdb_temp_medication
>>> SET `active` = IF(`h_number` IN ({$string}),'N','Y')");}
>>> --
>>> Rik Wasmus- Hide quoted text -
>>> - Show quoted text -
>> Thanks but this code does not retrieve the records for updating. How
>> do I proceed?- Hide quoted text -
>>
>> - Show quoted text -
>
> Ok, its not giving me any error, but its not updating either.
>

Your problem is right here:

echo "";

If any of the checkboxes are checked, you will get a zero-based index
array $_POST['stop']. This array will contain one element for each
checked box, and the contents of each element will be 'N' (the value=
parameter). Unchecked boxes will not be in the array.

I don't think this is what you want - there's no way to tell which boxes
are checked, since they all have the same name and the same value.

Probably you want something like:

echo
"";

(sorry for the wrap).

This will put your 'hos_no' in the $_POST['stop'] array for each checked
box.

Now you can update it with:

for each ($stop as $s)
{
$mysql_query="UPDATE irdb_temp_medication
SET active = 'N'
WHERE h_number = '$s')";
}

Or something similar. It's hard to tell from just partial code and no
database definitions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Updating Multiple Rolls Using PHP

am 23.08.2007 21:00:04 von chimambo

On 23 Aug, 17:00, Jerry Stuckle wrote:
> chima...@googlemail.com wrote:
> > On 23 Aug, 10:07, chima...@googlemail.com wrote:
> >> On 17 Aug, 15:58, Rik wrote:
>
> >>> On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
> >>>> Hi All,
> >>>> I have a little problem. I am retrieving records from a table and I
> >>>> want to update the records using checkboxes. I am able to display the
> >>>> database record quite alright and I have created an array of
> >>>> checkboxes, but my update loop is not working. Here is my code:
> >>>> /*---------This retrieves the records -------------*/
> >>>> if($row_md)
> >>>> {
> >>>> do{
> >>>> echo "";
> >>>> echo date('d-m-Y', strtotime($row_md['med_date']));
> >>>> echo "";
> >>>> echo "";
> >>>> echo $row_md['drug_desc'];
> >>>> echo "";
> >>>> echo "";
> >>>> echo $row_md['dose'];
> >>>> echo "";
> >>>> echo "";
> >>>> echo "=
";
> >>> (assuming a post)
> >>> echo " er']}'>";
> >>> (or whatever the primary key is called)
> >>>> echo "";
> >>>> }
> >>>> while($row_md =3D mysql_fetch_assoc($md));
> >>>> /*
> >>>> ------------------------------------------------------------ --------=
-------­­=AD--------------------
> >>>> */
> >>>> /*--------------This should update the records but its not working
> >>>> ----------*/
> >>>> while (list ($key,$val) =3D @each ($stop))
> >>>> {
> >>>> $mysql_query=3D"UPDATE irdb_temp_medication
> >>>> SET active =3D '$val'
> >>>> WHERE h_number =3D '$hos_no')";
> >>>> }
> >>> Assumptions:
> >>> 1. Form is posted.
> >>> 2. Primary key is h_number
> >>> 3. h_number is an integer
> >>> 4. You're trying to set `active` to 'N' (=3Dstop), else it would be '=
Y' =20
> >>> (=3Dstart).
> >>> if(isset($_POST['stop'])){
> >>> $off =3D array_map('intval',$_POST['stop']);
> >>> $string =3D implode(',',$off);
> >>> mysql_query("UPDATE irdb_temp_medication
> >>> SET active =3D 'N'
> >>> WHERE `h_number` IN ({$string})");
> >>> }
> >>> (If not-selected checkboxes should all be set to Y also:)
> >>> if(isset($_POST['stop']) && is_array($_POST['stop'])){
> >>> $off =3D array_map('intval',$_POST['stop']);
> >>> $string =3D implode(',',$off);
> >>> mysql_query("UPDATE irdb_temp_medication
> >>> SET `active` =3D IF(`h_number` IN ({$string})=
,'N','Y')");}
> >>> --
> >>> Rik Wasmus- Hide quoted text -
> >>> - Show quoted text -
> >> Thanks but this code does not retrieve the records for updating. How
> >> do I proceed?- Hide quoted text -
>
> >> - Show quoted text -
>
> > Ok, its not giving me any error, but its not updating either.
>
> Your problem is right here:
>
> echo "";
>
> If any of the checkboxes are checked, you will get a zero-based index
> array $_POST['stop']. This array will contain one element for each
> checked box, and the contents of each element will be 'N' (the value=3D
> parameter). Unchecked boxes will not be in the array.
>
> I don't think this is what you want - there's no way to tell which boxes
> are checked, since they all have the same name and the same value.
>
> Probably you want something like:
>
> echo
> " '>";
>
> (sorry for the wrap).
>
> This will put your 'hos_no' in the $_POST['stop'] array for each checked
> box.
>
> Now you can update it with:
>
> for each ($stop as $s)
> {
> $mysql_query=3D"UPDATE irdb_temp_medication
> SET active =3D 'N'
> WHERE h_number =3D '$s')";
>
> }
>
> Or something similar. It's hard to tell from just partial code and no
> database definitions.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -

Thanks but the value is not supposed to be hos_no because all the
records are based on the same hos_no. I have another key field though,
a sequence. Can I assume that I can replace the hos_no with the
sequence?

Re: Updating Multiple Rolls Using PHP

am 24.08.2007 02:15:51 von Jerry Stuckle

chimambo@googlemail.com wrote:
> On 23 Aug, 17:00, Jerry Stuckle wrote:
>> chima...@googlemail.com wrote:
>>> On 23 Aug, 10:07, chima...@googlemail.com wrote:
>>>> On 17 Aug, 15:58, Rik wrote:
>>>>> On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
>>>>>> Hi All,
>>>>>> I have a little problem. I am retrieving records from a table and I
>>>>>> want to update the records using checkboxes. I am able to display the
>>>>>> database record quite alright and I have created an array of
>>>>>> checkboxes, but my update loop is not working. Here is my code:
>>>>>> /*---------This retrieves the records -------------*/
>>>>>> if($row_md)
>>>>>> {
>>>>>> do{
>>>>>> echo "";
>>>>>> echo date('d-m-Y', strtotime($row_md['med_date']));
>>>>>> echo "";
>>>>>> echo "";
>>>>>> echo $row_md['drug_desc'];
>>>>>> echo "";
>>>>>> echo "";
>>>>>> echo $row_md['dose'];
>>>>>> echo "";
>>>>>> echo "";
>>>>>> echo "";
>>>>> (assuming a post)
>>>>> echo "";
>>>>> (or whatever the primary key is called)
>>>>>> echo "";
>>>>>> }
>>>>>> while($row_md = mysql_fetch_assoc($md));
>>>>>> /*
>>>>>> ------------------------------------------------------------ ---------------­­­--------------------
>>>>>> */
>>>>>> /*--------------This should update the records but its not working
>>>>>> ----------*/
>>>>>> while (list ($key,$val) = @each ($stop))
>>>>>> {
>>>>>> $mysql_query="UPDATE irdb_temp_medication
>>>>>> SET active = '$val'
>>>>>> WHERE h_number = '$hos_no')";
>>>>>> }
>>>>> Assumptions:
>>>>> 1. Form is posted.
>>>>> 2. Primary key is h_number
>>>>> 3. h_number is an integer
>>>>> 4. You're trying to set `active` to 'N' (=stop), else it would be 'Y'
>>>>> (=start).
>>>>> if(isset($_POST['stop'])){
>>>>> $off = array_map('intval',$_POST['stop']);
>>>>> $string = implode(',',$off);
>>>>> mysql_query("UPDATE irdb_temp_medication
>>>>> SET active = 'N'
>>>>> WHERE `h_number` IN ({$string})");
>>>>> }
>>>>> (If not-selected checkboxes should all be set to Y also:)
>>>>> if(isset($_POST['stop']) && is_array($_POST['stop'])){
>>>>> $off = array_map('intval',$_POST['stop']);
>>>>> $string = implode(',',$off);
>>>>> mysql_query("UPDATE irdb_temp_medication
>>>>> SET `active` = IF(`h_number` IN ({$string}),'N','Y')");}
>>>>> --
>>>>> Rik Wasmus- Hide quoted text -
>>>>> - Show quoted text -
>>>> Thanks but this code does not retrieve the records for updating. How
>>>> do I proceed?- Hide quoted text -
>>>> - Show quoted text -
>>> Ok, its not giving me any error, but its not updating either.
>> Your problem is right here:
>>
>> echo "";
>>
>> If any of the checkboxes are checked, you will get a zero-based index
>> array $_POST['stop']. This array will contain one element for each
>> checked box, and the contents of each element will be 'N' (the value=
>> parameter). Unchecked boxes will not be in the array.
>>
>> I don't think this is what you want - there's no way to tell which boxes
>> are checked, since they all have the same name and the same value.
>>
>> Probably you want something like:
>>
>> echo
>> "";
>>
>> (sorry for the wrap).
>>
>> This will put your 'hos_no' in the $_POST['stop'] array for each checked
>> box.
>>
>> Now you can update it with:
>>
>> for each ($stop as $s)
>> {
>> $mysql_query="UPDATE irdb_temp_medication
>> SET active = 'N'
>> WHERE h_number = '$s')";
>>
>> }
>>
>> Or something similar. It's hard to tell from just partial code and no
>> database definitions.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks but the value is not supposed to be hos_no because all the
> records are based on the same hos_no. I have another key field though,
> a sequence. Can I assume that I can replace the hos_no with the
> sequence?
>

If it's unique, you can. But as I said - from partial code and no
database info, it's impossible to tell.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Updating Multiple Rolls Using PHP

am 24.08.2007 09:55:53 von chimambo

On 24 Aug, 01:15, Jerry Stuckle wrote:
> chima...@googlemail.com wrote:
> > On 23 Aug, 17:00, Jerry Stuckle wrote:
> >> chima...@googlemail.com wrote:
> >>> On 23 Aug, 10:07, chima...@googlemail.com wrote:
> >>>> On 17 Aug, 15:58, Rik wrote:
> >>>>> On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
> >>>>>> Hi All,
> >>>>>> I have a little problem. I am retrieving records from a table and I
> >>>>>> want to update the records using checkboxes. I am able to display =
the
> >>>>>> database record quite alright and I have created an array of
> >>>>>> checkboxes, but my update loop is not working. Here is my code:
> >>>>>> /*---------This retrieves the records -------------*/
> >>>>>> if($row_md)
> >>>>>> {
> >>>>>> do{
> >>>>>> echo "";
> >>>>>> echo date('d-m-Y', strtotime($row_md['med_date']));
> >>>>>> echo "";
> >>>>>> echo "";
> >>>>>> echo $row_md['drug_desc'];
> >>>>>> echo "";
> >>>>>> echo "";
> >>>>>> echo $row_md['dose'];
> >>>>>> echo "";
> >>>>>> echo "";
> >>>>>> echo " '>";
> >>>>> (assuming a post)
> >>>>> echo " mber']}'>";
> >>>>> (or whatever the primary key is called)
> >>>>>> echo "";
> >>>>>> }
> >>>>>> while($row_md =3D mysql_fetch_assoc($md));
> >>>>>> /*
> >>>>>> ------------------------------------------------------------ ------=
---------­­­­--------------------
> >>>>>> */
> >>>>>> /*--------------This should update the records but its not working
> >>>>>> ----------*/
> >>>>>> while (list ($key,$val) =3D @each ($stop))
> >>>>>> {
> >>>>>> $mysql_query=3D"UPDATE irdb_temp_medication
> >>>>>> SET active =3D '$val'
> >>>>>> WHERE h_number =3D '$hos_no')";
> >>>>>> }
> >>>>> Assumptions:
> >>>>> 1. Form is posted.
> >>>>> 2. Primary key is h_number
> >>>>> 3. h_number is an integer
> >>>>> 4. You're trying to set `active` to 'N' (=3Dstop), else it would be=
'Y' =20
> >>>>> (=3Dstart).
> >>>>> if(isset($_POST['stop'])){
> >>>>> $off =3D array_map('intval',$_POST['stop']);
> >>>>> $string =3D implode(',',$off);
> >>>>> mysql_query("UPDATE irdb_temp_medication
> >>>>> SET active =3D 'N'
> >>>>> WHERE `h_number` IN ({$string})");
> >>>>> }
> >>>>> (If not-selected checkboxes should all be set to Y also:)
> >>>>> if(isset($_POST['stop']) && is_array($_POST['stop'])){
> >>>>> $off =3D array_map('intval',$_POST['stop']);
> >>>>> $string =3D implode(',',$off);
> >>>>> mysql_query("UPDATE irdb_temp_medication
> >>>>> SET `active` =3D IF(`h_number` IN ({$string=
}),'N','Y')");}
> >>>>> --
> >>>>> Rik Wasmus- Hide quoted text -
> >>>>> - Show quoted text -
> >>>> Thanks but this code does not retrieve the records for updating. How
> >>>> do I proceed?- Hide quoted text -
> >>>> - Show quoted text -
> >>> Ok, its not giving me any error, but its not updating either.
> >> Your problem is right here:
>
> >> echo "";
>
> >> If any of the checkboxes are checked, you will get a zero-based index
> >> array $_POST['stop']. This array will contain one element for each
> >> checked box, and the contents of each element will be 'N' (the value=
=3D
> >> parameter). Unchecked boxes will not be in the array.
>
> >> I don't think this is what you want - there's no way to tell which box=
es
> >> are checked, since they all have the same name and the same value.
>
> >> Probably you want something like:
>
> >> echo
> >> " ]"'>";
>
> >> (sorry for the wrap).
>
> >> This will put your 'hos_no' in the $_POST['stop'] array for each check=
ed
> >> box.
>
> >> Now you can update it with:
>
> >> for each ($stop as $s)
> >> {
> >> $mysql_query=3D"UPDATE irdb_temp_medication
> >> SET active =3D 'N'
> >> WHERE h_number =3D '$s')";
>
> >> }
>
> >> Or something similar. It's hard to tell from just partial code and no
> >> database definitions.
>
> >> --
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> ==================- Hide quoted te=
xt -
>
> >> - Show quoted text -
>
> > Thanks but the value is not supposed to be hos_no because all the
> > records are based on the same hos_no. I have another key field though,
> > a sequence. Can I assume that I can replace the hos_no with the
> > sequence?
>
> If it's unique, you can. But as I said - from partial code and no
> database info, it's impossible to tell.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -

I think I am almost there. But I am getting an error:

Notice: Undefined variable: stop in X:\othe...ation.php on line 112
Warning: Invalid argument supplied for foreach() in X:
\othe...ation.php on line 112

If I use $stop. However is I use foreach ($_POST['stop'] as $s) ... I
get:

Warning: Invalid argument supplied for foreach() in X:
\othe...ation.php on line 112

Please help were I am going wrong.

Re: Updating Multiple Rolls Using PHP

am 24.08.2007 13:37:15 von Jerry Stuckle

chimambo@googlemail.com wrote:
> On 24 Aug, 01:15, Jerry Stuckle wrote:
>> chima...@googlemail.com wrote:
>>> On 23 Aug, 17:00, Jerry Stuckle wrote:
>>>> chima...@googlemail.com wrote:
>>>>> On 23 Aug, 10:07, chima...@googlemail.com wrote:
>>>>>> On 17 Aug, 15:58, Rik wrote:
>>>>>>> On Fri, 17 Aug 2007 16:25:36 +0200, wrote:
>>>>>>>> Hi All,
>>>>>>>> I have a little problem. I am retrieving records from a table and I
>>>>>>>> want to update the records using checkboxes. I am able to display the
>>>>>>>> database record quite alright and I have created an array of
>>>>>>>> checkboxes, but my update loop is not working. Here is my code:
>>>>>>>> /*---------This retrieves the records -------------*/
>>>>>>>> if($row_md)
>>>>>>>> {
>>>>>>>> do{
>>>>>>>> echo "";
>>>>>>>> echo date('d-m-Y', strtotime($row_md['med_date']));
>>>>>>>> echo "";
>>>>>>>> echo "";
>>>>>>>> echo $row_md['drug_desc'];
>>>>>>>> echo "";
>>>>>>>> echo "";
>>>>>>>> echo $row_md['dose'];
>>>>>>>> echo "";
>>>>>>>> echo "";
>>>>>>>> echo "";
>>>>>>> (assuming a post)
>>>>>>> echo "";
>>>>>>> (or whatever the primary key is called)
>>>>>>>> echo "";
>>>>>>>> }
>>>>>>>> while($row_md = mysql_fetch_assoc($md));
>>>>>>>> /*
>>>>>>>> ------------------------------------------------------------ ---------------­­­­--------------------
>>>>>>>> */
>>>>>>>> /*--------------This should update the records but its not working
>>>>>>>> ----------*/
>>>>>>>> while (list ($key,$val) = @each ($stop))
>>>>>>>> {
>>>>>>>> $mysql_query="UPDATE irdb_temp_medication
>>>>>>>> SET active = '$val'
>>>>>>>> WHERE h_number = '$hos_no')";
>>>>>>>> }
>>>>>>> Assumptions:
>>>>>>> 1. Form is posted.
>>>>>>> 2. Primary key is h_number
>>>>>>> 3. h_number is an integer
>>>>>>> 4. You're trying to set `active` to 'N' (=stop), else it would be 'Y'
>>>>>>> (=start).
>>>>>>> if(isset($_POST['stop'])){
>>>>>>> $off = array_map('intval',$_POST['stop']);
>>>>>>> $string = implode(',',$off);
>>>>>>> mysql_query("UPDATE irdb_temp_medication
>>>>>>> SET active = 'N'
>>>>>>> WHERE `h_number` IN ({$string})");
>>>>>>> }
>>>>>>> (If not-selected checkboxes should all be set to Y also:)
>>>>>>> if(isset($_POST['stop']) && is_array($_POST['stop'])){
>>>>>>> $off = array_map('intval',$_POST['stop']);
>>>>>>> $string = implode(',',$off);
>>>>>>> mysql_query("UPDATE irdb_temp_medication
>>>>>>> SET `active` = IF(`h_number` IN ({$string}),'N','Y')");}
>>>>>>> --
>>>>>>> Rik Wasmus- Hide quoted text -
>>>>>>> - Show quoted text -
>>>>>> Thanks but this code does not retrieve the records for updating. How
>>>>>> do I proceed?- Hide quoted text -
>>>>>> - Show quoted text -
>>>>> Ok, its not giving me any error, but its not updating either.
>>>> Your problem is right here:
>>>> echo "";
>>>> If any of the checkboxes are checked, you will get a zero-based index
>>>> array $_POST['stop']. This array will contain one element for each
>>>> checked box, and the contents of each element will be 'N' (the value=
>>>> parameter). Unchecked boxes will not be in the array.
>>>> I don't think this is what you want - there's no way to tell which boxes
>>>> are checked, since they all have the same name and the same value.
>>>> Probably you want something like:
>>>> echo
>>>> "";
>>>> (sorry for the wrap).
>>>> This will put your 'hos_no' in the $_POST['stop'] array for each checked
>>>> box.
>>>> Now you can update it with:
>>>> for each ($stop as $s)
>>>> {
>>>> $mysql_query="UPDATE irdb_temp_medication
>>>> SET active = 'N'
>>>> WHERE h_number = '$s')";
>>>> }
>>>> Or something similar. It's hard to tell from just partial code and no
>>>> database definitions.
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================- Hide quoted text -
>>>> - Show quoted text -
>>> Thanks but the value is not supposed to be hos_no because all the
>>> records are based on the same hos_no. I have another key field though,
>>> a sequence. Can I assume that I can replace the hos_no with the
>>> sequence?
>> If it's unique, you can. But as I said - from partial code and no
>> database info, it's impossible to tell.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -
>
> I think I am almost there. But I am getting an error:
>
> Notice: Undefined variable: stop in X:\othe...ation.php on line 112
> Warning: Invalid argument supplied for foreach() in X:
> \othe...ation.php on line 112
>
> If I use $stop. However is I use foreach ($_POST['stop'] as $s) ... I
> get:
>
> Warning: Invalid argument supplied for foreach() in X:
> \othe...ation.php on line 112
>
> Please help were I am going wrong.
>
>

It's saying $_POST['stop'] is not an array. Maybe it's a scalar or not
even defined in the $_POST array. But whatever you use in the foreach
(...) statement must itself be an array.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Updating Multiple Rolls Using PHP

am 27.08.2007 18:11:24 von chimambo

On 24 Aug, 13:37, Jerry Stuckle wrote:
> chima...@googlemail.com wrote:
> > On 24 Aug, 01:15, Jerry Stuckle wrote:
> >> chima...@googlemail.com wrote:
> >>> On 23 Aug, 17:00, Jerry Stuckle wrote:
> >>>> chima...@googlemail.com wrote:
> >>>>> On 23 Aug, 10:07, chima...@googlemail.com wrote:
> >>>>>> On 17 Aug, 15:58, Rik wrote:
> >>>>>>> On Fri, 17 Aug 2007 16:25:36 +0200, wro=
te:
> >>>>>>>> Hi All,
> >>>>>>>> I have a little problem. I am retrieving records from a table an=
d I
> >>>>>>>> want to update the records using checkboxes. I am able to displa=
y the
> >>>>>>>> database record quite alright and I have created an array of
> >>>>>>>> checkboxes, but my update loop is not working. Here is my code:
> >>>>>>>> /*---------This retrieves the records -------------*/
> >>>>>>>> if($row_md)
> >>>>>>>> {
> >>>>>>>> do{
> >>>>>>>> echo "";
> >>>>>>>> echo date('d-m-Y', strtotime($row_md['med_date']));
> >>>>>>>> echo "";
> >>>>>>>> echo "";
> >>>>>>>> echo $row_md['drug_desc'];
> >>>>>>>> echo "";
> >>>>>>>> echo "";
> >>>>>>>> echo $row_md['dose'];
> >>>>>>>> echo "";
> >>>>>>>> echo "";
> >>>>>>>> echo " 'N'>";
> >>>>>>> (assuming a post)
> >>>>>>> echo " number']}'>";
> >>>>>>> (or whatever the primary key is called)
> >>>>>>>> echo "";
> >>>>>>>> }
> >>>>>>>> while($row_md =3D mysql_fetch_assoc($md));
> >>>>>>>> /*
> >>>>>>>> ------------------------------------------------------------ ----=
-----------­­­­=AD--------------------
> >>>>>>>> */
> >>>>>>>> /*--------------This should update the records but its not worki=
ng
> >>>>>>>> ----------*/
> >>>>>>>> while (list ($key,$val) =3D @each ($stop))
> >>>>>>>> {
> >>>>>>>> $mysql_query=3D"UPDATE irdb_temp_medication
> >>>>>>>> SET active =3D '$val'
> >>>>>>>> WHERE h_number =3D '$hos_no')";
> >>>>>>>> }
> >>>>>>> Assumptions:
> >>>>>>> 1. Form is posted.
> >>>>>>> 2. Primary key is h_number
> >>>>>>> 3. h_number is an integer
> >>>>>>> 4. You're trying to set `active` to 'N' (=3Dstop), else it would =
be 'Y' =20
> >>>>>>> (=3Dstart).
> >>>>>>> if(isset($_POST['stop'])){
> >>>>>>> $off =3D array_map('intval',$_POST['stop']);
> >>>>>>> $string =3D implode(',',$off);
> >>>>>>> mysql_query("UPDATE irdb_temp_medication
> >>>>>>> SET active =3D 'N'
> >>>>>>> WHERE `h_number` IN ({$string})");
> >>>>>>> }
> >>>>>>> (If not-selected checkboxes should all be set to Y also:)
> >>>>>>> if(isset($_POST['stop']) && is_array($_POST['stop'])){
> >>>>>>> $off =3D array_map('intval',$_POST['stop']);
> >>>>>>> $string =3D implode(',',$off);
> >>>>>>> mysql_query("UPDATE irdb_temp_medication
> >>>>>>> SET `active` =3D IF(`h_number` IN ({$stri=
ng}),'N','Y')");}
> >>>>>>> --
> >>>>>>> Rik Wasmus- Hide quoted text -
> >>>>>>> - Show quoted text -
> >>>>>> Thanks but this code does not retrieve the records for updating. H=
ow
> >>>>>> do I proceed?- Hide quoted text -
> >>>>>> - Show quoted text -
> >>>>> Ok, its not giving me any error, but its not updating either.
> >>>> Your problem is right here:
> >>>> echo "";
> >>>> If any of the checkboxes are checked, you will get a zero-based index
> >>>> array $_POST['stop']. This array will contain one element for each
> >>>> checked box, and the contents of each element will be 'N' (the value=
=3D
> >>>> parameter). Unchecked boxes will not be in the array.
> >>>> I don't think this is what you want - there's no way to tell which b=
oxes
> >>>> are checked, since they all have the same name and the same value.
> >>>> Probably you want something like:
> >>>> echo
> >>>> " o']."'>";
> >>>> (sorry for the wrap).
> >>>> This will put your 'hos_no' in the $_POST['stop'] array for each che=
cked
> >>>> box.
> >>>> Now you can update it with:
> >>>> for each ($stop as $s)
> >>>> {
> >>>> $mysql_query=3D"UPDATE irdb_temp_medication
> >>>> SET active =3D 'N'
> >>>> WHERE h_number =3D '$s')";
> >>>> }
> >>>> Or something similar. It's hard to tell from just partial code and =
no
> >>>> database definitions.
> >>>> --
> >>>> ==================
> >>>> Remove the "x" from my email address
> >>>> Jerry Stuckle
> >>>> JDS Computer Training Corp.
> >>>> jstuck...@attglobal.net
> >>>> ==================- Hide quoted =
text -
> >>>> - Show quoted text -
> >>> Thanks but the value is not supposed to be hos_no because all the
> >>> records are based on the same hos_no. I have another key field though,
> >>> a sequence. Can I assume that I can replace the hos_no with the
> >>> sequence?
> >> If it's unique, you can. But as I said - from partial code and no
> >> database info, it's impossible to tell.
>
> >> --
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> ==================- Hide quoted te=
xt -
>
> >> - Show quoted text -
>
> > I think I am almost there. But I am getting an error:
>
> > Notice: Undefined variable: stop in X:\othe...ation.php on line 112
> > Warning: Invalid argument supplied for foreach() in X:
> > \othe...ation.php on line 112
>
> > If I use $stop. However is I use foreach ($_POST['stop'] as $s) ... I
> > get:
>
> > Warning: Invalid argument supplied for foreach() in X:
> > \othe...ation.php on line 112
>
> > Please help were I am going wrong.
>
> It's saying $_POST['stop'] is not an array. Maybe it's a scalar or not
> even defined in the $_POST array. But whatever you use in the foreach
> (...) statement must itself be an array.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -

Thanks for your help Jerry. I used the while loop with what you
suggested on the checkbox, i.e.:
echo " $row_md['hos_no']."'>";
And it worked. Thanks once more.