The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Checkboxes and Queries help
This is driving me krazy.
I have a table with some data which is put into an array, and displayed as checkboxes. Now I have a separate table, which holds the data the user has selected (based on the checkbox options). What would be the best way to display them both? IE, show the "options" and also show what the user has selected? Many thanks |
#2
|
||||
|
||||
you could left join the tables in a query
|
#3
|
||||
|
||||
Can you give me an example of how to Left Join properly? I did queries ages ago and can't remember how, and almost all interent resources I looked at are confusing
Cheers |
#4
|
||||
|
||||
$DB_site->query("SELECT * FROM blah WHERE blah1='1234' LEFT JOIN blahothertable ON (blah.blah1.=blahothertable.blah6)");
i think thats correct but dont trust me 100% more like 80% try phpfreaks.com or mysqlfreaks.com |
#5
|
||||
|
||||
Left join will not work. That is, if you plan to show all the option fields. If you just want to grab the options that the user has "checked" in checkbox, then you can use a left join. You will have to make 2 queries.
Can you explain more about this table for holding the options? Such as, what fields it contains. Also, are you selecting just one user from the user-table (e.g. $DB_site->query_first) or selecting more than one? (e.g. $DB_site->query) |
#6
|
||||
|
||||
Appreciate the helps guys.
It's an abilities hack, for RPG boards and the likes. It has 2 tables - rpgabilities and rpguserabilities. rpgabilities - fields are abid (ability id - auto increments), name (name of ability), and description (describe what it does) rpguserabilities - fields are id (unique, auto increments), username (name of user who is learning/has learnt the ability, name (name of ability), abexp (the exp the user has for that ability) and checked (yes no value for the checkbox). Yup I will be using 1 user from the user table (where username = $bbuserinfo[name] i think) - it will show only the abilities of the member. |
#7
|
||||
|
||||
*Bump* please help
Thanks |
#8
|
||||
|
||||
You need to query the option table, then make a separate query for the user, then iterate through all the query options and when you come to one that the user has checked, you simply add the checked="checked" attribute to that checkbox tag. You can hold that bit of information in a variable, so to use it in a template.
I don't have time to write out the code for you, but I'll see what I can do later today if you still need help. |
#9
|
||||
|
||||
I think I get what you mean - just don't understand how to do it.
It'd be great if you could provide some code to help, but I will try and do it myself too and see what i come up with. Cheers again |
#10
|
||||
|
||||
Your table setup for `rpguserabilities` is a bit ackward.
You have the field called `checked`, although shouldn't it be implicit that a user has an ability simply if the row exists? (since the row contains the ability name) ? If I were you, I'd make the `rpguserabilities`contain the ability name for a field, but also the ability id (or just the ability id, incase you ever change the ability name you wouldn't want to have to update every row), and drop the `checked`. Then you could use the following. PHP Code:
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|