Forum Moderators: coopster

Message Too Old, No Replies

php checkbox array from multiple tables

save/obtain two properites for a checkbox

         

jasons

8:07 pm on Feb 14, 2006 (gmt 0)

10+ Year Member



hi, all,

I am having a little problem here. What I have now is a list of items built from multiple tables from a database. Now I want to build a sql query based on the user selection. the problem is if all items were from the same table, that is easy, a checkbox array do. but here, I also need to know the table name that corresponds to each item/checkbox. is there any way to do it?

thanks a lot if someone can show me how to do this?

jatar_k

8:56 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld jasons,

is there any correlation bwtween the checkbox names and the table names?

jasons

10:34 pm on Feb 14, 2006 (gmt 0)

10+ Year Member



because I don't know apriori the table names (loaded fromthe database dependent on previous input), i would build an array ID like below,
<input type='checkbox' name='ID[]' value='1' />category 1
<input type='checkbox' name='ID[]' value='2' />category 2
<input type='checkbox' name='ID[]' value='3' />category 3
with ID referring to the ID of item within a specific table. Then in order to find the item, I need to know the name of the table specific to that item.

with the table names known, I can build a search query by going through each item.

I was thinking about two ways of doing this: one is using 'class', like
<input type='checkbox' name='ID[]' value='1' class='table1' />category 1
but i am not sure how to locate it.

another way is to use ID as a 2-d array, but I am not sure how. any idea?

jatar_k

11:06 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my first thought would to hybridize the id

id:tablename

or something like that and make that the value of the checkbox

jasons

11:39 pm on Feb 14, 2006 (gmt 0)

10+ Year Member



thanks, Jatar.

you mean:
<input type='checkbox' name='ID[]' value='1:table1' />category 1
?

i think this will do.

jatar_k

12:20 am on Feb 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



exactly like that

coopster

5:25 pm on Feb 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The multidimensional array option would work too. There is an often overlooked page in the PHP manual that really helps new users understand how PHP and HTML [php.net] interact.