Painful problem for ya :)

This is a discussion on Painful problem for ya :) within the PHP Language forums, part of the PHP Programming Forums category; I have which has dynamic checkboxes named "holdtalent" which have the value from a recordset "talent_id". ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-08-2005
RelaxoRy
 
Posts: n/a
Default Painful problem for ya :)

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 :)
Reply With Quote
  #2 (permalink)  
Old 01-08-2005
Janwillem Borleffs
 
Posts: n/a
Default Re: Painful problem for ya :)

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



Reply With Quote
  #3 (permalink)  
Old 01-08-2005
kicken
 
Posts: n/a
Default Re: Painful problem for ya :)

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.
Reply With Quote
  #4 (permalink)  
Old 01-08-2005
CJ Llewellyn
 
Posts: n/a
Default Re: Painful problem for ya :)

"RelaxoRy" <relaxory@postmaster.co.uk> wrote in message
news:3ba42c06.0501080650.35e04e4a@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";



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:32 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0