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

Reply
 
Thread Tools Display Modes
  #1  
Old 11-06-2009, 11:04 PM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default More efficient way to code?

Is there a more efficient way to code this? I'm still learning.

PHP Code:
if ($_POST['do'] == 'edit')
{
$vbulletin->input->clean_array_gpc('p', array(
'image_1' => TYPE_NOHTML,
'url_1' => TYPE_NOHTML,
'subtitle_1' => TYPE_NOHTML,
'title_1' => TYPE_NOHTML,
'id_1' => TYPE_INT,
'image_2' => TYPE_NOHTML,
'url_2' => TYPE_NOHTML,
'subtitle_2' => TYPE_NOHTML,
'title_2' => TYPE_NOHTML,
'id_2' => TYPE_INT,
'image_3' => TYPE_NOHTML,
'url_4' => TYPE_NOHTML,
'subtitle_3' => TYPE_NOHTML,
'title_3' => TYPE_NOHTML,
'id_3' => TYPE_INT,
'image_4' => TYPE_NOHTML,
'url_4' => TYPE_NOHTML,
'subtitle_4' => TYPE_NOHTML,
'title_4' => TYPE_NOHTML,
'id_4' => TYPE_INT,
'image_5' => TYPE_NOHTML,
'url_5' => TYPE_NOHTML,
'subtitle_5' => TYPE_NOHTML,
'title_5' => TYPE_NOHTML,
'id_5' => TYPE_INT
    
));
    
    
$db->query_write("UPDATE featured_band SET title = '".$vbulletin->GPC['title_1']."', subtitle = '".$vbulletin->GPC['subtitle_1']."', url = '".$vbulletin->GPC['url_1']."', image = '".$vbulletin->GPC['image_1']."'    WHERE id =".$vbulletin->GPC['id_1']."");
    
    
$db->query_write("UPDATE featured_band SET title = '".$vbulletin->GPC['title_2']."', subtitle = '".$vbulletin->GPC['subtitle_2']."', url = '".$vbulletin->GPC['url_2']."', image = '".$vbulletin->GPC['image_2']."'    WHERE id =".$vbulletin->GPC['id_2']."");
    
    
$db->query_write("UPDATE featured_band SET title = '".$vbulletin->GPC['title_3']."', subtitle = '".$vbulletin->GPC['subtitle_3']."', url = '".$vbulletin->GPC['url_3']."', image = '".$vbulletin->GPC['image_3']."'    WHERE id =".$vbulletin->GPC['id_3']."");
    
    
$db->query_write("UPDATE featured_band SET title = '".$vbulletin->GPC['title_4']."', subtitle = '".$vbulletin->GPC['subtitle_4']."', url = '".$vbulletin->GPC['url_4']."', image = '".$vbulletin->GPC['image_4']."'    WHERE id =".$vbulletin->GPC['id_4']."");
    
    
$db->query_write("UPDATE featured_band SET title = '".$vbulletin->GPC['title_5']."', subtitle = '".$vbulletin->GPC['subtitle_5']."', url = '".$vbulletin->GPC['url_5']."', image = '".$vbulletin->GPC['image_5']."'    WHERE id =".$vbulletin->GPC['id_5']."");
    
    
$vbulletin->url "/index.php?" $vbulletin->session->vars['sessionurl'];  
    eval(
print_standard_redirect('usercss_saved'));
    exit;

PHP Code:
echo '<form action="fb.php" method="post"><input type="hidden" name="do" value="edit" /><div style="height:350px; overflow:auto; padding:0 8px 0px 0px;"><div class="round alt1 twelve" style="padding:8px;margin-top:4px;border:1px solid #dcdcdc">';

$editfeature $vbulletin->db->query_read("SELECT * FROM featured_band ORDER BY id LIMIT 5");

while (
$entry $vbulletin->db->fetch_array($editfeature))
{

echo 
'<div class="boxhead">Spot '.$entry['id'].'</div>
<div class="menu_nl"><div style="float:left;">Title:</div><div align="right"><input name="title_'
.$entry['id'].'" type="text" class="bginput" size="40" value="'.$entry['title'].'"></div></div>
<div class="menu_nl"><div style="float:left;">Sub-Title:</div><div align="right"><input name="subtitle_'
.$entry['id'].'" type="text" class="bginput" size="40" value="'.$entry['subtitle'].'"></div></div>
<div class="menu_nl"><div style="float:left;">Link:</div><div align="right"><input name="url_'
.$entry['id'].'" type="text" class="bginput" size="40" value="'.$entry['url'].'"></div></div>
<div class="menu_nl"><div style="float:left;">URL to Image:</div><div align="right"><input name="image_'
.$entry['id'].'" type="text" class="bginput" size="40" value="'.$entry['image'].'"></div><br />Note: Must be 414 pixels wide by 173 pixels high.</div><input type="hidden" name="id_'.$entry['id'].'" value="'.$entry['id'].'" />';

}

echo 
'</div></div>';

echo 
'<div align="center" style="padding-top:8px;"><input name="" class="btnb" type="submit" value="Save Changes"></div></form>'
Reply With Quote
  #2  
Old 11-07-2009, 12:08 AM
Brandon_R Brandon_R is offline
 
Join Date: Aug 2009
Posts: 63
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Take a look into the following functions:

For Each
For
Reply With Quote
  #3  
Old 11-07-2009, 04:16 AM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Brandon_R View Post
Take a look into the following functions:

For Each
For
Where would that go?
Reply With Quote
  #4  
Old 11-07-2009, 04:29 AM
Wired1's Avatar
Wired1 Wired1 is offline
 
Join Date: Nov 2003
Location: Orlando, FL, USA
Posts: 1,361
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would use it or another loop for the query writes.
Reply With Quote
  #5  
Old 11-07-2009, 04:35 AM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmm, I think I understand - but don't know how to make it do what I want ...
Reply With Quote
  #6  
Old 11-09-2009, 04:58 PM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:


$arr 
= array(12345);
foreach (
$arr as $value) {
   
$db->query_write("UPDATE featured_band SET title = '".$vbulletin->GPC['title_$value']."', subtitle = '".$vbulletin->GPC['subtitle_$value']."', url = '".$vbulletin->GPC['url_$value']."', image = '".$vbulletin->GPC['image_$value']."'    WHERE id =".$vbulletin->GPC['id_$value']."");
}
unset(
$value); 
??
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 02:33 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.03789 seconds
  • Memory Usage 2,258KB
  • 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
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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