By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Updating Multiple Rolls Using PHP

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.