View Single Post
  #5  
Old 08-20-2011, 03:31 PM
Iain M's Avatar
Iain M Iain M is offline
 
Join Date: Jul 2005
Location: Glasgow, Scotland
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That would be great thanks =] I'll try and figure it out tho.

--------------- Added [DATE]1313870349[/DATE] at [TIME]1313870349[/TIME] ---------------

Ok.. got somewhere.

I have my fields named as: gender[{vb:raw id}], free[{vb:raw id}], active[{vb:raw id}]

and my inputs being validated:
PHP Code:
            $vbulletin->input->clean_array_gpc('p', array(
                
'gender'    => TYPE_ARRAY_UINT,
                
'free'    => TYPE_ARRAY_UINT,
                
'active'    => TYPE_ARRAY_UINT,
            )); 
Now it's figuring out how to post the data to the database. I've had a look at the foreach, but I think that'd require foreach loops for each array?
PHP Code:
$i 1/* for illustrative purposes only */

foreach ($vbulletin->GPC['gender'] as $gender) {
    echo 
"\$vbulletin->GPC['gender'][$i] => $gender.\n";
    
$i++;

Which outputs:
Code:
$vbulletin->GPC['gender'][1] => 3. $vbulletin->GPC['gender'][2] => 3. $vbulletin->GPC['gender'][3] => 3.
Is there a way to merge them together or another way of doing it?

--------------- Added [DATE]1313874927[/DATE] at [TIME]1313874927[/TIME] ---------------

Got it working! Thanks for your help Marco.

So, you don't need multiple foreach loops, you just put your array in the first one. Here's the full working code if anyone's interested:
PHP Code:
    if($_REQUEST['action'] == "updatenames")
    {
        
// Clean parameters
        
$vbulletin->input->clean_array_gpc('p', array(
            
'gender'    => TYPE_ARRAY_UINT,
            
'free'    => TYPE_ARRAY_UINT,
            
'active'    => TYPE_ARRAY_UINT,
        )); 

        
// Get the oldest ID
        
$oldestID $db->query_first("SELECT id FROM " TABLE_PREFIX "names WHERE userid = '" $vbulletin->userinfo['userid'] . "' ORDER BY id ASC");        
        
$i $oldestID['id'];

        
// Loop through and update each record
        
foreach ($vbulletin->GPC['gender'] as $gender)
        {
            
// Easy names
            
$free $vbulletin->GPC['free'][$i];
            
$active $vbulletin->GPC['active'][$i];

            
$db->query_write("
                UPDATE " 
TABLE_PREFIX "names
                SET gender = '
$gender',
                    free = '
$free',
                    active = '
$active'
                WHERE id = '
$i'
            "
);
            
$i++;
        }
        
        
// Redirect to view changes
        
$vbulletin->url="names.php?" $vbulletin->session->vars['sessionurl'] . "do=viewnames";
        eval(
print_standard_redirect('names_updated'truetrue));        
    } 
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01975 seconds
  • Memory Usage 1,805KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete