Re: [PHP] Best way to reinstate radio-button states from database?

2009-06-30 Thread Tom Worster
On 6/29/09 10:26 PM, Michael A. Peters mpet...@mac.com wrote:

 Rob Gould wrote:
 I have a webpage which allows people to log in and make selections with
 radio buttons and hit SUBMIT and saves the data from those radio buttons
 to a mySQL database.
 
 However, I'm finding that I also need the ability to allow a user to log
 back in at a later date (or even on a different computer), and pull up
 that survey again,
 with each of the 50-something radio-buttons back in the positions in
 which they were last saved.
 
 Surely there's a best-case-method for doing this type of thing (saving
 large numbers of radio-button-group settings to mySQL and pulling them back
 again later).  Any advice is greatly appreciated.  Perhaps there's a
 jQuery-way to retrieve all the radio-button group settings as an array
 and save it and pull it back again?
 Or perhaps a PHP-specific method - - - I'm fine with either.
 
 
 Generate your radio list via php.
 When the value grabbed from database matches the button value, add a
 selected=selected to the radio input.
 
 Works for me.

michael: radios and checkboxes take the checked attribute -- options in
selects take the selected attribute.
http://www.w3.org/TR/html401/interact/forms.html#checkbox

rob: if you use systematic naming of the radio input elements (e.g. a common
prefix) then you can use a simple loop to generate an SQL query from the
$_POST array to store the form state as a string. then use another loop to
generate the markup for all your radios, inserting the checked attribute for
those radios whose names appear in the string you stored in the DB. the key
is the systematic naming and having a page design (and maybe template
scheme, if you like) that allows simple automated generation of the form's
markup. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to reinstate radio-button states from database?

2009-06-30 Thread Michael A. Peters

Tom Worster wrote:
*snip*


michael: radios and checkboxes take the checked attribute -- options in
selects take the selected attribute.


Doh - I knew that.
Typo. I always thought it silly there were two different attributes 
anyway, when they basically are same thing and can never both occur in 
same tag.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to reinstate radio-button states from database?

2009-06-29 Thread Ashley Sheridan
On Sun, 2009-06-28 at 21:07 -0400, Bastien Koert wrote:
 On Sun, Jun 28, 2009 at 7:12 PM, Rob Gouldgould...@mac.com wrote:
  I have a webpage which allows people to log in and make selections with
  radio buttons and hit SUBMIT and saves the data from those radio buttons to
  a mySQL database.
 
  However, I'm finding that I also need the ability to allow a user to log
  back in at a later date (or even on a different computer), and pull up that
  survey again,
  with each of the 50-something radio-buttons back in the positions in which
  they were last saved.
 
  Surely there's a best-case-method for doing this type of thing (saving large
  numbers of radio-button-group settings to mySQL and pulling them back
  again later).  Any advice is greatly appreciated.  Perhaps there's a
  jQuery-way to retrieve all the radio-button group settings as an array and
  save it and pull it back again?
  Or perhaps a PHP-specific method - - - I'm fine with either.
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 I've tended to use a binary string for the values, as my radio/
 checkboxs tend to be yes / no, so I store the data in a single field
 as 010111010101010111000 using 0=no and 1=yes.
 
 Then a quick loop through the string sets my values.
 
 
 -- 
 
 Bastien
 
 Cat, the other other white meat
 

Or use a separate survey table to store each answer, and associate it
with the user by the index on the users table.

Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to reinstate radio-button states from database?

2009-06-29 Thread tedd

At 7:12 PM -0400 6/28/09, Rob Gould wrote:
I have a webpage which allows people to log in and make selections 
with radio buttons and hit SUBMIT and saves the data from those 
radio buttons to a mySQL database.


However, I'm finding that I also need the ability to allow a user to 
log back in at a later date (or even on a different computer), and 
pull up that survey again,
with each of the 50-something radio-buttons back in the positions in 
which they were last saved.


Surely there's a best-case-method for doing this type of thing 
(saving large numbers of radio-button-group settings to mySQL and 
pulling them back
again later).  Any advice is greatly appreciated.  Perhaps there's a 
jQuery-way to retrieve all the radio-button group settings as an 
array and save it and pull it back again?

Or perhaps a PHP-specific method - - - I'm fine with either.


Rob:

I don't know the best way, but this is the way I do it.

My database is relational. Each user has an unique ID as well as each 
question has a unique ID and the answer to each question is the one 
of several different choices (1 to whatever).


Each answer is recorded in the database as a *separate* record that 
contains the user ID, question ID and their choice. A record might 
look like this:


Table: answers
Fields: user_id, question_id, answer
Values: 34,115,5

That's where 34 is the user's ID, 115 is the question's ID, and 5 is 
the user's choice.


Then whenever you wanted to pull out and show the user (user 34 for 
example) what they picked, just select all the records that have a 
user ID of 34 and sort them by question ID and show the selections 
the user made.


If you have different test, then add a unique test_id field and make 
the question_id non-unique. An example might be:


Table: answers
Fields: user_id, test_id, question_id, answer
Values: 34,20,11,5

That's where 34 is the user's ID, 20 is the test's ID, 11 is the 
question's ID, and 5 is the user's choice.


Then you could pull out all records that have the same user ID and 
test ID and show the questions and answers associated with that test 
and that user.


That works for me.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to reinstate radio-button states from database?

2009-06-29 Thread Michael A. Peters

Rob Gould wrote:
I have a webpage which allows people to log in and make selections with 
radio buttons and hit SUBMIT and saves the data from those radio buttons 
to a mySQL database.


However, I'm finding that I also need the ability to allow a user to log 
back in at a later date (or even on a different computer), and pull up 
that survey again,
with each of the 50-something radio-buttons back in the positions in 
which they were last saved.


Surely there's a best-case-method for doing this type of thing (saving 
large numbers of radio-button-group settings to mySQL and pulling them back
again later).  Any advice is greatly appreciated.  Perhaps there's a 
jQuery-way to retrieve all the radio-button group settings as an array 
and save it and pull it back again?

Or perhaps a PHP-specific method - - - I'm fine with either.





Generate your radio list via php.
When the value grabbed from database matches the button value, add a 
selected=selected to the radio input.


Works for me.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Best way to reinstate radio-button states from database?

2009-06-28 Thread Rob Gould
I have a webpage which allows people to log in and make selections  
with radio buttons and hit SUBMIT and saves the data from those radio  
buttons to a mySQL database.


However, I'm finding that I also need the ability to allow a user to  
log back in at a later date (or even on a different computer), and  
pull up that survey again,
with each of the 50-something radio-buttons back in the positions in  
which they were last saved.


Surely there's a best-case-method for doing this type of thing (saving  
large numbers of radio-button-group settings to mySQL and pulling them  
back
again later).  Any advice is greatly appreciated.  Perhaps there's a  
jQuery-way to retrieve all the radio-button group settings as an array  
and save it and pull it back again?

Or perhaps a PHP-specific method - - - I'm fine with either.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to reinstate radio-button states from database?

2009-06-28 Thread Bastien Koert
On Sun, Jun 28, 2009 at 7:12 PM, Rob Gouldgould...@mac.com wrote:
 I have a webpage which allows people to log in and make selections with
 radio buttons and hit SUBMIT and saves the data from those radio buttons to
 a mySQL database.

 However, I'm finding that I also need the ability to allow a user to log
 back in at a later date (or even on a different computer), and pull up that
 survey again,
 with each of the 50-something radio-buttons back in the positions in which
 they were last saved.

 Surely there's a best-case-method for doing this type of thing (saving large
 numbers of radio-button-group settings to mySQL and pulling them back
 again later).  Any advice is greatly appreciated.  Perhaps there's a
 jQuery-way to retrieve all the radio-button group settings as an array and
 save it and pull it back again?
 Or perhaps a PHP-specific method - - - I'm fine with either.



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



I've tended to use a binary string for the values, as my radio/
checkboxs tend to be yes / no, so I store the data in a single field
as 010111010101010111000 using 0=no and 1=yes.

Then a quick loop through the string sets my values.


-- 

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php