Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2011, 07:12 PM
wpeloquin wpeloquin is offline
 
Join Date: May 2006
Location: Behind you...
Posts: 143
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP: 1 array being used by multiple loops.

To start, yes I am a novice at this and am currently learning.

I am having difficulty getting a single array to work in multiple places. i have a table with a list of classes in it, and i pull that into an array. i then want to use the data in that array to make multiple <select> form options. This code that i have works with one <select> but leaves the others blank. If i make 3 arrays, one for each, then it all works. Is it not possible to use just 1 array to knock out some of the redundancy of the code?

here is the code:
Code:
$my_classall = $vbulletin->db->query_read("
	SELECT class_id, class_name
	FROM " . TABLE_PREFIX . "my_table_class AS my_table_class
	ORDER BY class_name ASC
");


while ($my_class1 = $vbulletin->db->fetch_array($my_classall))
{
	$my_class1_name = $my_class1['class_name'];
	eval('$my_class1selector .= " <option value=\"'.$my_class1['class_id'].'\" " . iif($my_toon[class_1]==$my_class1[class_id]," selected=\"selected\"","").">'.htmlspecialchars($my_class1['class_name']).'</option> ";');
}


while ($my_class2 = $vbulletin->db->fetch_array($my_classall))
{
	$my_class2_name = $my_class2['class_name'];
	eval('$my_class2selector .= " <option value=\"'.$my_class2['class_id'].'\" " . iif($my_toon[class_2]==$my_class2[class_id]," selected=\"selected\"","").">'.htmlspecialchars($my_class2['class_name']).'</option> ";');
}
Reply With Quote
  #2  
Old 02-03-2011, 07:51 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I can't say that I know exactly what you want to do because it looks like you're trying to build exactly the same string twice, which seems unnecessary. But I think what you have posted above doesn't work because you're doing the query, looping through the results, then trying to loop through them again (which I don't think will work, I think you'd have to perform the query again).

If you want to have more than one select, why not just use the same string of options for both? Or if the options aren't really supposed to be exactly the same, you could build both strings in the same loop.
Reply With Quote
  #3  
Old 02-04-2011, 09:31 AM
wpeloquin wpeloquin is offline
 
Join Date: May 2006
Location: Behind you...
Posts: 143
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

the object, in this case a character, will be able to have up to 3 classes. when a user goes back to edit a character, the <select> option that was input will be the default option, based on the iif statement in the eval. since there are 3 possible classes, there needs to be 3 distinct select menus, even though the menus have the same data.

are you saying that the 3 different name and eval statements can all be put in the same loop? i have not tried that, will try it later today.
Reply With Quote
  #4  
Old 02-04-2011, 11:02 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by wpeloquin View Post
since there are 3 possible classes, there needs to be 3 distinct select menus, even though the menus have the same data.
I see now - my mistake, I missed the "iff" part.

Quote:
are you saying that the 3 different name and eval statements can all be put in the same loop?
Yeah, that should work.
Reply With Quote
  #5  
Old 02-06-2011, 01:17 AM
wpeloquin wpeloquin is offline
 
Join Date: May 2006
Location: Behind you...
Posts: 143
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much
Reply With Quote
Reply


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:56 PM.


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.03852 seconds
  • Memory Usage 2,202KB
  • 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_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete