On Friday, February 1, 2002, at 06:05  PM, Georgie Casey wrote:

> OK, I've a page for my users to sign up on my website and in the form,
> there's a few checkboxes fields. So I set the name of the check boxes as
> name[] and PHP made an array of all the options choosen. All the check 
> boxes
> values are numbers, so I got all the numbers from the array, put a comma
> between them all and inserted them as one field in my database. Easy.

Sometimes, when working with RDBMS, you don't want to take shortcuts 
like this -- by entering disparate data into one field, that you wish to 
then pull from the database and use as separate entities (you want to 
populate each checkbox with a check for each number that is stored).  In 
the future, you may wish to plan your database so that it stores each 
checked value in a separate field, or some other more elegant scheme for 
data storage.  Just advice to keep in mind for the future.

> It worked well. But now I've a problem. I want to give users the option 
> of
> changing their details when they log into the site. So I get the form 
> and
> put <?php echo $variable_name; ?> in every text box so the user sees 
> their
> record. I had a small problem with showing choosen values in dropdown 
> lists
> and radio options but i solved them both.

In order to pull that comma-delimited database record for that user from 
the database and use it to populate each checkbox that deserves a check, 
what you will need to do is this:

1) use a SQL query to extract the record for the user
2) use PHP function explode() to separate the record into an array with 
the numbers as separate elements.  Use the comma to delimit the 
explode() function, since you've stored your data with commas.
3) Now you've got an array full of values for the user's checked boxes.  
You probably want to run the array through a WHILE loop that prints the 
appropriate check box, and sets the attribute  checked="yes" for each 
box within the loop that has a corresponding value in the record from 
the SQL query.

Hope this helps, and if not, post some code since we have to answer this 
question in the abstract.


Erik




----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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

Reply via email to