Creating a new array dynamically for checkboxes?

Reply

Join Date: Jul 2007
Posts: 3
Reputation: concordia is an unknown quantity at this point 
Solved Threads: 0
concordia concordia is offline Offline
Newbie Poster

Creating a new array dynamically for checkboxes?

 
0
  #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!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #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 Quick reply to this message  
Join Date: Jul 2007
Posts: 3
Reputation: concordia is an unknown quantity at this point 
Solved Threads: 0
concordia concordia is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #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 Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #4
Jul 17th, 2007
I suppose you could stuff all of the data into something like
  1. $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 Quick reply to this message  
Join Date: Jul 2007
Posts: 8
Reputation: MB1765 is an unknown quantity at this point 
Solved Threads: 0
MB1765 MB1765 is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #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 Quick reply to this message  
Join Date: Jul 2007
Posts: 8
Reputation: MB1765 is an unknown quantity at this point 
Solved Threads: 0
MB1765 MB1765 is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #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 Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: sonyparekh is an unknown quantity at this point 
Solved Threads: 0
sonyparekh's Avatar
sonyparekh sonyparekh is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #7
Nov 21st, 2008
I am not able to retrieve check boxes from the databases. I have done as far as what the thread says.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: sonyparekh is an unknown quantity at this point 
Solved Threads: 0
sonyparekh's Avatar
sonyparekh sonyparekh is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #8
Nov 21st, 2008
I am not able to retrieve the check boxes from the database for some reason.. I have done stuff so far as what this thread reads.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: sonyparekh is an unknown quantity at this point 
Solved Threads: 0
sonyparekh's Avatar
sonyparekh sonyparekh is offline Offline
Newbie Poster

Re: Creating a new array dynamically for checkboxes?

 
0
  #9
Nov 21st, 2008
Hey it works now.. I had an extremely minute error
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC