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

Painful problem for ya :)

P: n/a
I have which has dynamic checkboxes named "holdtalent" which have the
value from a recordset "talent_id". I have a query to a recordset
getting the checkboxs state. If "Y" it is ticked, if "N" it is not
ticked.

This works fine and the data displays as does the checkbox state.

If I untick a checkbox, I want to update the database with "N". an
unticked checkbox doesnt send anything through $_POST so how do I get
the change in there?

I thought maybe.. I have recordset with the talent_id and the state
already there. If I refine that recordset to only give me the checked
values "Y" into a new array, then when the form is posted back with no
corresponding value but was "Y" in the recordset, then it must have
been unchecked, so update that row with "N" as the state.

But whats teh code to do eeet?

Also, if I have a recordset I'm paging through, with checkboxes, and I
check some on one page, then page through again and select some more,
how do I get those pre-selected values? Each time I page through it
doesnt remember the previous pages values.

I thought maybe dynamically setting the state of the checkbox with a
session variable. Then each time a "Next Page" link is clicked, it
submits the form recording the session state for that pages buttons.
But If I have a lot of data, I'll have a tonne of session variables.
And then how would I differentiate between when a form is submitted by
a button or a "Next Page" link?

I really dont want to use javascript to write the cookies each time a
checkbox is clicked as it might be incompatible with browser setups.

Another way would be perhaps parseing it into the querystring..
".php?cb1=y&cb4=n" etc but I have a string limit. There won't be THAT
many records, but I want the perfect solution.

Heeeeeeeeeeeelp :)
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
RelaxoRy wrote:
If I untick a checkbox, I want to update the database with "N". an
unticked checkbox doesnt send anything through $_POST so how do I get
the change in there?


The following would be the easiest:

if (!isset($_POST['holdtalent'])) $_POST['holdtalent'] = 'N';

A nicer approach, however, is to set a default for the table field (alter
table sometable change field field varchar(3) default 'N'). Then you would
only include this field in your query when $_POST['holdtalent'] has been
set...
JW

Jul 17 '05 #2

P: n/a
RelaxoRy wrote:
I have which has dynamic checkboxes named "holdtalent" which have the
value from a recordset "talent_id". I have a query to a recordset
getting the checkboxs state. If "Y" it is ticked, if "N" it is not
ticked.

This works fine and the data displays as does the checkbox state.

If I untick a checkbox, I want to update the database with "N". an
unticked checkbox doesnt send anything through $_POST so how do I get
the change in there?


What I would probably do is just include a hidden field with ALL the
ID's together, separated by a space. Then you can take that field and
for every checkbox that is returned, remove that ID from the field's
list. After you have processed the checkboxes, the field would then
containe a list of those checkboxes that were displayed, but not checked
by the user. Pretty simple and effective.
Jul 17 '05 #3

P: n/a
"RelaxoRy" <re******@postmaster.co.uk> wrote in message
news:3b**************************@posting.google.c om...
I have which has dynamic checkboxes named "holdtalent" which have the
value from a recordset "talent_id". I have a query to a recordset
getting the checkboxs state. If "Y" it is ticked, if "N" it is not
ticked.

This works fine and the data displays as does the checkbox state.

If I untick a checkbox, I want to update the database with "N". an
unticked checkbox doesnt send anything through $_POST so how do I get
the change in there?


You need to build a list of records that are to updated with Y, and then use
that list in a positive and negative fashion.

$aVar = array(
1 => 1, 3 => 1, 5 => 1, 6 => 1);

$reclist = '';
$sep = '';
foreach($aVar as $k => $v)
{
$reclist .= sprintf(" %s id = '%s'",
$sep, $k);
$sep = 'OR';
}

$sql = sprintf("UPDATE tablename SET fieldname='N' WHERE !(%s)" ,
$reclist);
echo $sql . "\n";
$sql = sprintf("UPDATE tablename SET fieldname='Y' WHERE (%s)",
$reclist);
echo $sql . "\n";

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.