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 04-20-2004, 04:03 PM
ixian's Avatar
ixian ixian is offline
 
Join Date: Oct 2001
Location: Denver, CO
Posts: 189
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP - using variable to limit output in url problem

Say I have this code:

PHP Code:
   {  
           
$sqlstr .= " AND bugs.stateid=$state";  
    } 
Which does the following: When a link has the specific stateid in it, such as

www.test.com/bugs.php?state=1

Only items with a state of "1" are returned. This works just dandy.

Now, what I want to do is code it so that I can have a url that returns all states BUT 1. So for example, if I want to view states 1 and 2, but not 3. This is to hide tickets with a "closed" state (state 3) in vbbugs, in case anyone was wondering.

I've come up with this:

PHP Code:
 if ($state)  
     {  
      if( 
$state == "active" )  
       {  
        
$sqlstr .= " AND bugs.stateid!=3";  
       }  
   else  
    {  
           
$sqlstr .= " AND bugs.stateid=$state";  
    }  
     } 
Where, if the url www.test.com/bugs.php?state=active was received, all states but state 3 would be displayed, but that doesn't seem to be working.

Obviously there is a mistake there, but I can't spot it. Any ideas? Or even a better way to do this? All I am trying to do in the end is give an option to hide closed bugs/tickets from the default display.

Thanks
Reply With Quote
  #2  
Old 04-20-2004, 04:06 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try changing this:

PHP Code:
$sqlstr .= " AND bugs.stateid!=3"
to this:

PHP Code:
$sqlstr .= " AND bugs.stateid!='3'"
Reply With Quote
  #3  
Old 04-20-2004, 04:17 PM
ixian's Avatar
ixian ixian is offline
 
Join Date: Oct 2001
Location: Denver, CO
Posts: 189
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That had no effect, alas. What's weird about this is I get no error message or anything; it just doesn't hide the state.
Reply With Quote
  #4  
Old 04-20-2004, 04:20 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nope, the value without the ' was correct.

but before the whole if construct you have to put
PHP Code:
$state $_GET['state']; 
Reply With Quote
  #5  
Old 04-20-2004, 04:27 PM
ixian's Avatar
ixian ixian is offline
 
Join Date: Oct 2001
Location: Denver, CO
Posts: 189
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Curses! That didn't do it either.

Any chance I could attach the file here and have one of you take a quick look at it? I can't believe I'm having so much trouble with such a simple feature
Reply With Quote
  #6  
Old 04-21-2004, 04:56 PM
ixian's Avatar
ixian ixian is offline
 
Join Date: Oct 2001
Location: Denver, CO
Posts: 189
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Figured it out.

The problem was the quotes around "active" if anyone runs into something similar in the future. Removed the quotes and it works now.
Reply With Quote
  #7  
Old 04-21-2004, 05:18 PM
AlexanderT's Avatar
AlexanderT AlexanderT is offline
 
Join Date: Mar 2003
Posts: 294
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ixian, maybe a bit off-topic, but you should really santize your code, especially when you use URL parameters in your mysql instruction, to prevent something like a sql injection attack!
Reply With Quote
  #8  
Old 04-21-2004, 05:37 PM
ixian's Avatar
ixian ixian is offline
 
Join Date: Oct 2001
Location: Denver, CO
Posts: 189
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you offer tips for the examples above? I freely admit to still being in the "learning" stage here. Any advice would be greatly appreciated.
Reply With Quote
  #9  
Old 04-21-2004, 08:45 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Take a look at the globalize() function in includes/functions.php and how vB uses it. For the above example with state:

PHP Code:
globalize($_REQUEST, array('state' => STR_NOHTML)); 
Basicly means, take the variable index with the name state, from the $_REQUEST array (ie $_REQUEST['state']) make it a string with HTML removed with the variablt name $state
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 10:27 PM.


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.04055 seconds
  • Memory Usage 2,251KB
  • 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
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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