User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,141 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,688 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2194 | Replies: 5
Reply
Join Date: Jul 2007
Posts: 3
Reputation: concordia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
concordia concordia is offline Offline
Newbie Poster

Question Creating a new array dynamically for checkboxes?

  #1  
Jul 17th, 2007
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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,840
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 283
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Creating a new array dynamically for checkboxes?

  #2  
Jul 17th, 2007
Why is the name of your internal variable for storing the checkbox array important to what the user sees? I guess I'm missing that part.
Reply With Quote  
Join Date: Jul 2007
Posts: 3
Reputation: concordia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
concordia concordia is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

  #3  
Jul 17th, 2007
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.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,840
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 283
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Creating a new array dynamically for checkboxes?

  #4  
Jul 17th, 2007
I suppose you could stuff all of the data into something like
$data[$category][$subcategory][$entry]
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.
Reply With Quote  
Join Date: Jul 2007
Posts: 8
Reputation: MB1765 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
MB1765 MB1765 is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

  #5  
Jul 22nd, 2007
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
Reply With Quote  
Join Date: Jul 2007
Posts: 8
Reputation: MB1765 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
MB1765 MB1765 is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

  #6  
Jul 22nd, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC