473,484 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating Multiple Rolls Using PHP

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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
echo "</td></tr>";
}
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')";
}

Aug 17 '07 #1
10 2213
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
echo "</td></tr>";
}
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')";

}- Hide quoted text -

- Show quoted text -
How is $stop getting a value?

Aug 17 '07 #2
Rik
On Fri, 17 Aug 2007 16:25:36 +0200, <ch******@googlemail.comwrote:
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
(assuming a post)

echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
echo "</td></tr>";
}
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
Aug 17 '07 #3
On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";

(assuming a post)

echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
echo "</td></tr>";
}
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?
Aug 23 '07 #4
On 23 Aug, 10:07, chima...@googlemail.com wrote:
On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:


On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
(assuming a post)
echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
echo "</td></tr>";
}
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.

Aug 23 '07 #5
ch******@googlemail.com wrote:
On 23 Aug, 10:07, chima...@googlemail.com wrote:
>On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:


>>On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
(assuming a post)
echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
echo "</td></tr>";
}
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 "<input type='checkbox' name=stop[] value='N'>";

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
"<input type='checkbox' name=stop[] value='".$row_md['hos_no']."'>";

(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.
js*******@attglobal.net
==================
Aug 23 '07 #6
On 23 Aug, 17:00, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 23 Aug, 10:07, chima...@googlemail.com wrote:
On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:
>On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
(assuming a post)
echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
echo "</td></tr>";
}
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 "<input type='checkbox' name=stop[] value='N'>";

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
"<input type='checkbox' name=stop[] value='".$row_md['hos_no']."'>";

(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?

Aug 23 '07 #7
ch******@googlemail.com wrote:
On 23 Aug, 17:00, Jerry Stuckle <jstuck...@attglobal.netwrote:
>chima...@googlemail.com wrote:
>>On 23 Aug, 10:07, chima...@googlemail.com wrote:
On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
>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 "<tr><td text align='right'>";
> echo date('d-m-Y', strtotime($row_md['med_date']));
> echo "</td>";
> echo "<td text align='left'>";
> echo $row_md['drug_desc'];
> echo "</td>";
> echo "<td text align='left'>";
> echo $row_md['dose'];
> echo "</td>";
> echo "<td>";
> echo "<input type='checkbox' name=stop[] value='N'>";
(assuming a post)
echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
> echo "</td></tr>";
> }
> 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 "<input type='checkbox' name=stop[] value='N'>";

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
"<input type='checkbox' name=stop[] value='".$row_md['hos_no']."'>";

(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.
js*******@attglobal.net
==================
Aug 24 '07 #8
On 24 Aug, 01:15, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 23 Aug, 17:00, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 23 Aug, 10:07, chima...@googlemail.com wrote:
On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
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 "<tr><td text align='right'>";
echo date('d-m-Y', strtotime($row_md['med_date']));
echo "</td>";
echo "<td text align='left'>";
echo $row_md['drug_desc'];
echo "</td>";
echo "<td text align='left'>";
echo $row_md['dose'];
echo "</td>";
echo "<td>";
echo "<input type='checkbox' name=stop[] value='N'>";
(assuming a post)
echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
(or whatever the primary key is called)
echo "</td></tr>";
}
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 "<input type='checkbox' name=stop[] value='N'>";
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
"<input type='checkbox' name=stop[] value='".$row_md['hos_no']."'>";
(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.
Aug 24 '07 #9
ch******@googlemail.com wrote:
On 24 Aug, 01:15, Jerry Stuckle <jstuck...@attglobal.netwrote:
>chima...@googlemail.com wrote:
>>On 23 Aug, 17:00, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 23 Aug, 10:07, chima...@googlemail.com wrote:
>On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:
>>On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
>>>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 "<tr><td text align='right'>";
>>> echo date('d-m-Y', strtotime($row_md['med_date']));
>>> echo "</td>";
>>> echo "<td text align='left'>";
>>> echo $row_md['drug_desc'];
>>> echo "</td>";
>>> echo "<td text align='left'>";
>>> echo $row_md['dose'];
>>> echo "</td>";
>>> echo "<td>";
>>> echo "<input type='checkbox' name=stop[] value='N'>";
>>(assuming a post)
>>echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
>>(or whatever the primary key is called)
>>> echo "</td></tr>";
>>> }
>>> 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 "<input type='checkbox' name=stop[] value='N'>";
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
"<input type='checkbox' name=stop[] value='".$row_md['hos_no']."'>";
(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.
js*******@attglobal.net
==================
Aug 24 '07 #10
On 24 Aug, 13:37, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 24 Aug, 01:15, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 23 Aug, 17:00, Jerry Stuckle <jstuck...@attglobal.netwrote:
chima...@googlemail.com wrote:
On 23 Aug, 10:07, chima...@googlemail.com wrote:
On 17 Aug, 15:58, Rik <luiheidsgoe...@hotmail.comwrote:
>On Fri, 17 Aug 2007 16:25:36 +0200, <chima...@googlemail.comwrote:
>>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 "<tr><td text align='right'>";
>> echo date('d-m-Y', strtotime($row_md['med_date']));
>> echo "</td>";
>> echo "<td text align='left'>";
>> echo $row_md['drug_desc'];
>> echo "</td>";
>> echo "<td text align='left'>";
>> echo $row_md['dose'];
>> echo "</td>";
>> echo "<td>";
>> echo "<input type='checkbox' name=stop[] value='N'>";
>(assuming a post)
>echo "<input type='checkbox' name='stop[]' value='{$row['h_number']}'>";
>(or whatever the primary key is called)
>> echo "</td></tr>";
>> }
>> 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 "<input type='checkbox' name=stop[] value='N'>";
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
"<input type='checkbox' name=stop[] value='".$row_md['hos_no']."'>";
(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.
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 "<input type='checkbox' name=stop[] value='".
$row_md['hos_no']."'>";
And it worked. Thanks once more.

Aug 27 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2037
by: Roy Adams | last post by:
Hi everyone I'm trying to build a shopping cart app using a db the part I'm stuck on is the fact that, if someone adds a product that they have previously added to the cart. I've got it set up to...
3
12990
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
2
1465
by: Gaurav Vaish | last post by:
Hi, How can I accomplish multiple authentication modes in one application? I have the following scenario: - A company, X, has some employees - Those on rolls have an AD account - Those...
14
2911
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
34
10765
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
6
4059
by: muttu2244 | last post by:
hi all am updating the same file in ftp, through multiple clients, but am scared that two clients may open the same file at a time, and try updating, then the data updated by one data will be...
2
2246
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
1
1946
by: batista | last post by:
Hello all, I have a third praty grid control...named C1grid. Im using it in one of my apps.. Now, I have bind this grid to a custom dataset class named "DataViewEx". The code of the class is...
2
2618
by: julie18881 | last post by:
I may be being really stupid here, i have spent the last 3 hours looking round your site and some other for answers to my problem, but have not had much luck (possibly cuase my brain just isn't...
0
6950
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7103
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7140
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6811
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5403
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4841
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1355
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.