Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2004, 11:35 PM
geniuscrew's Avatar
geniuscrew geniuscrew is offline
 
Join Date: Nov 2001
Location: UK
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 03-22-2004, 12:37 AM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you could left join the tables in a query
Reply With Quote
  #3  
Old 03-22-2004, 01:21 AM
geniuscrew's Avatar
geniuscrew geniuscrew is offline
 
Join Date: Nov 2001
Location: UK
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 03-22-2004, 01:25 AM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$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
Reply With Quote
  #5  
Old 03-22-2004, 01:53 AM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #6  
Old 03-22-2004, 08:49 AM
geniuscrew's Avatar
geniuscrew geniuscrew is offline
 
Join Date: Nov 2001
Location: UK
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 03-23-2004, 10:01 AM
geniuscrew's Avatar
geniuscrew geniuscrew is offline
 
Join Date: Nov 2001
Location: UK
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*Bump* please help

Thanks
Reply With Quote
  #8  
Old 03-23-2004, 01:20 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 03-23-2004, 04:38 PM
geniuscrew's Avatar
geniuscrew geniuscrew is offline
 
Join Date: Nov 2001
Location: UK
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 03-23-2004, 05:59 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$abilities $DB_site->query("
                SELECT abid, name, description 
                FROM `abilities`"
);

$user $DB_site->query_first("
                SELECT id, username, name, abid, abexp
                FROM `userabilities` 
                WHERE id=
$bbuserinfo[userid]");

while (
$ability $DB-site->fetch_array($abilities))
{
    if (
$user['abid'] == $ability['abid'])
    {
        
$is_checked ' checked="checked"';  // to be used in template
        // or substitute a template:
        // eval('$is_checked = "'.fetch_template('template_is_checked') . '";');
    
}

    eval(
'$option_row .= "'.fetch_template('template_option_row') . '";');
    
// this template contains the checkbox input information (name, description),
    // and the $is_checked variable
    
    
unset($is_checked);  // make sure to delete $is_checked
}

eval(
"dooutput(\"".gettemplate('template_options')."\");");
// output main template 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04363 seconds
  • Memory Usage 2,260KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete