| | |
Creating a new array dynamically for checkboxes?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Solved Threads: 0
Hi all!
I am totally stumped and am hoping someone can help me. I have some data in a database that I will be using to create checkboxes. However, since different data will be pulled out depending on what the user chooses, I want to be able to create the name of my checkboxes based on what they want (which is also in a database), ie instead of hardcoding name="checkbox[]", I want to be able to make it name="whatcomesoutofdb[]"
Does that make sense? I cant seem to figure out how to make it work and maybe it's not possible. I've tried a variable of variables but that doesn't seem to work for array. Any help would be great!
Thanks!
I am totally stumped and am hoping someone can help me. I have some data in a database that I will be using to create checkboxes. However, since different data will be pulled out depending on what the user chooses, I want to be able to create the name of my checkboxes based on what they want (which is also in a database), ie instead of hardcoding name="checkbox[]", I want to be able to make it name="whatcomesoutofdb[]"
Does that make sense? I cant seem to figure out how to make it work and maybe it's not possible. I've tried a variable of variables but that doesn't seem to work for array. Any help would be great!
Thanks!
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Solved Threads: 0
Thanks for your reply! Ah, I was thinking that I would name the internal array variable with key IDs that correspond to the entries in my database. That way when I get the results, I'll be able to insert into my database easily. At least that's what I thought.
I don't know if this will clarify much, but here is what I'm trying to do. I'm creating a questionnaire and all of the items that a user can select are stored in a database. I then want to be able to record what each user selected and dump it out later by user. The questionnaire is grouped by different categories and subcategories, which is what each array variable will hold. Ideally, I'd like to just create one page that will ask the right question based on the $_GET variable (which will be the category) passed in the URL. It worked perfect when I hardcoded everything, but a database will make managing my data a lot easier.
I think my problem is that I have 4 subcategories per category and would like it all to show up on one page. I suppose if I just had one subcategory per page, this wouldn't be a problem.
Man, I probably just made this more confusing.
I don't know if this will clarify much, but here is what I'm trying to do. I'm creating a questionnaire and all of the items that a user can select are stored in a database. I then want to be able to record what each user selected and dump it out later by user. The questionnaire is grouped by different categories and subcategories, which is what each array variable will hold. Ideally, I'd like to just create one page that will ask the right question based on the $_GET variable (which will be the category) passed in the URL. It worked perfect when I hardcoded everything, but a database will make managing my data a lot easier.
I think my problem is that I have 4 subcategories per category and would like it all to show up on one page. I suppose if I just had one subcategory per page, this wouldn't be a problem.
Man, I probably just made this more confusing.
I suppose you could stuff all of the data into something like but I'm not sure if that will make it easier or more difficult for you to manage 
The display part would be pretty easy at that point, since it only requires a series of nested for loop to generate output. Not knowing the database structure it's harder to say if you can push the data into the structure quite as easily from your queries.
Just a thought.
PHP Syntax (Toggle Plain Text)
$data[$category][$subcategory][$entry]

The display part would be pretty easy at that point, since it only requires a series of nested for loop to generate output. Not knowing the database structure it's harder to say if you can push the data into the structure quite as easily from your queries.
Just a thought.
•
•
Join Date: Jul 2007
Posts: 8
Reputation:
Solved Threads: 0
I think I experinced your problem, so try my remedy :
1st define a variable ase name of your checkbox
2nd assign what else that pulled out ... to that varialbe, thus you have a check box which has different name depending on what the user chooses.
like this:
$query = select * from ... ;
$result = mysql_query( $query, "sqlLink" );
$getResult = mysql_fetch_array( $result );
name = $getResult["..."];
I hope it helps to you
1st define a variable ase name of your checkbox
2nd assign what else that pulled out ... to that varialbe, thus you have a check box which has different name depending on what the user chooses.
like this:
$query = select * from ... ;
$result = mysql_query( $query, "sqlLink" );
$getResult = mysql_fetch_array( $result );
name = $getResult["..."];
I hope it helps to you
•
•
Join Date: Jul 2007
Posts: 8
Reputation:
Solved Threads: 0
I think I experinced your problem, so try my remedy :
1st define a variable ase name of your checkbox
2nd assign what else that pulled out ... to that variable, thus you have a check box which has different name depending on what the user chooses.
like this:
$query = select * from ... ;
$result = mysql_query( $query, "sqlLink" );
$getResult = mysql_fetch_array( $result );
name = $getResult["..."];
I hope it helps to you
1st define a variable ase name of your checkbox
2nd assign what else that pulled out ... to that variable, thus you have a check box which has different name depending on what the user chooses.
like this:
$query = select * from ... ;
$result = mysql_query( $query, "sqlLink" );
$getResult = mysql_fetch_array( $result );
name = $getResult["..."];
I hope it helps to you
![]() |
Similar Threads
- How to get value of selected dynamic checkboxes? (ASP.NET)
- Creating dynamic array structures (C++)
- ArrayList to multi-dimensional string array (C#)
- URGENT - Reading from txt file into a 2 dimension array (Java)
Other Threads in the PHP Forum
- Previous Thread: passing directory name as a variable in include function
- Next Thread: Parse error: syntax error, unexpected T_VARIABLE in C:\ on line 46
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link list login mail mediawiki menu mlm multiple mycodeisbad mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search seo server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign websphere white xml youtube






