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 07-11-2005, 09:08 AM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default what's wrong with this query?

even when i use the echo to read it via the top of the page it stops at the table prefix.

[sql] SELECT username, userid, email
FROM prs_users
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = prs_users.userid)
WHERE prs_users.subscriptions LIKE = "% $display[pieceid] %" AND userid != $getparentinfo[userid]
[/sql]

and i'm calling it like this
PHP Code:
        $thesubscribed $DB_site->query("
            SELECT username, userid, email
            FROM prs_users
            LEFT JOIN " 
TABLE_PREFIX "user AS user ON (user.userid = prs_user.userid)
            WHERE prs_users.subscriptions LIKE = "
$display[pieceid] %" AND userid != $getparentinfo[userid]
        "
); 
Reply With Quote
  #2  
Old 07-11-2005, 12:16 PM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could you post the exact error message?

Also, could it be that prs_users also needs a TABLE_PREFIX?
Reply With Quote
  #3  
Old 07-11-2005, 12:26 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

here you go
PHP Code:
Database error in vBulletin 3.0.7:

Invalid SQL
            
SELECT usernameuseridemail
            FROM prs_users
            LEFT JOIN 
mysql error
You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

mysql error number
1064 
and nope prs_users has no table prefix what so ever
Reply With Quote
  #4  
Old 07-11-2005, 12:35 PM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Tough to say, however it would at least read a little better and be easier to troubleshoot written like this:

PHP Code:
$thesubscribed $DB_site->query(
            SELECT p.username, p.userid, p.email 
            FROM prs_users p 
            LEFT JOIN " 
TABLE_PREFIX "user u ON p.userid = u.userid 
            WHERE p.subscriptions LIKE '%
$display[pieceid]%' AND u.userid != $getparentinfo[userid] 
        "
); 
I dont know if thats right - nor do I know if I got the fields on the right aliases (p for prd_users and u for users).
Hell, this may actually make it harder for you to troubleshoot - I just thought I would trow it in as its the style I would use.

I point to note is that "% $display[pieceid] %" would have given you problems for a number of reasons (in fact, it shouldnt have compiled).

HTH's m8
Reply With Quote
  #5  
Old 07-11-2005, 12:40 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

funnily enough i just changed it to read a bit better with this
PHP Code:
        $thesubscribed $DB_site->query("
            SELECT user.username, prs_users.userid, user.email
            FROM prs_users
            LEFT JOIN " 
TABLE_PREFIX "user AS user ON (user.userid = prs_users.userid)
            WHERE prs_users.subscriptions LIKE = "
$display[pieceid] %" AND prs_users.userid != $getparentinfo[userid]
        "
); 
and i know all the colums are there so it's just confusing me.

Quote:
Originally Posted by The Geek
I point to note is that "% $display[pieceid] %" would have given you problems for a number of reasons (in fact, it shouldnt have compiled).
you're right the single quotes fixed it, thank you

though now i'm getting
Code:
Database error in vBulletin 3.0.7:

Invalid SQL: 
			SELECT user.username, prs_users.userid, user.email
			FROM prs_users
			LEFT JOIN user AS user ON (user.userid = prs_users.userid)
			WHERE prs_users.subscriptions LIKE = '% 1 %' AND prs_users.userid != 0
		
mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '% 1 %' AND prs_users.userid != 0' at line 4

mysql error number: 1064
not sure what that means

nevermind the problem was the = <--- thanks again
Reply With Quote
  #6  
Old 07-11-2005, 01:09 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The best and most valid way to write this query would be:

[SQL]$thesubscribed = $DB_site->query
("
SELECT p.username, p.userid, p.email
FROM prs_users p
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = p.userid)
WHERE p.subscriptions LIKE '%" . $display[pieceid] . "%' AND p.userid != '" . $getparentinfo[userid] . "'
");[/SQL]
Reply With Quote
  #7  
Old 07-11-2005, 01:42 PM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dark Visor
The best and most valid way to write this query would be:

[SQL]$thesubscribed = $DB_site->query
("
SELECT p.username, p.userid, p.email
FROM prs_users p
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = p.userid)
WHERE p.subscriptions LIKE '%" . $display[pieceid] . "%' AND p.userid != '" . $getparentinfo[userid] . "'
");[/SQL]
I like to have "FROM prs_users AS p", but it's not as if it would make a difference.
Reply With Quote
  #8  
Old 07-11-2005, 01:44 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dark Visor
The best and most valid way to write this query would be: [SQL]$thesubscribed = $DB_site->query("SELECT p.username, p.userid, p.emailFROM prs_users pLEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = p.userid)WHERE p.subscriptions LIKE '%" . $display[pieceid] . "%' AND p.userid != '" . $getparentinfo[userid] . "'");[/SQL]
Most valid would be using also $display['pieceid'] instead of $display[pieceid]. And depending on the column type and where that value is coming from, maybe also measurements to avoid injections, and amybe more but that is difficult to tell based on the info we have.


ohh and yes like mentioned before, TABLE_PREFIX on all tables.
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 01:52 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.04567 seconds
  • Memory Usage 2,249KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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_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