vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   More efficient way to code? (https://vborg.vbsupport.ru/showthread.php?t=227523)

noonespecial 11-06-2009 11:04 PM

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>'


Brandon_R 11-07-2009 12:08 AM

Take a look into the following functions:

For Each
For

noonespecial 11-07-2009 04:16 AM

Quote:

Originally Posted by Brandon_R (Post 1911156)
Take a look into the following functions:

For Each
For

Where would that go?

Wired1 11-07-2009 04:29 AM

You would use it or another loop for the query writes.

noonespecial 11-07-2009 04:35 AM

Hmmm, I think I understand - but don't know how to make it do what I want ...

noonespecial 11-09-2009 04:58 PM

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); 

??


All times are GMT. The time now is 08:20 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01194 seconds
  • Memory Usage 1,776KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete