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

Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2005, 03:02 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Adding Query into showthread.php

How would I add :

PHP Code:
if ($threadid == 1)
{
$gettitle mysql_query("SELECT * from USER where USERNAME='$post[title]'");
$postloser mysql_fetch_array($gettitle);

...into showthread.php to be defined while in the post stuff.

(So in each post it will work depending on what the title is (which will be someones username).

I tried looking for a place to stick it in, but of course the vb code for that page is much more complicated than mine. :ermm:
Reply With Quote
  #2  
Old 01-29-2005, 03:07 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should not use mySQL-functions directly - use the class provided by vBulletin.
Furthermore, this would be highly inefficient, as it adds a query for every post.
Reply With Quote
  #3  
Old 01-29-2005, 03:11 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay I'll try to explain what I'm doing so hopefully one of you can give me a push in the right direction.

In the given thread the title input is a dropdown of the member list, then when they post it sets the title as that. I added into the postbit 'Accept' / 'Decline' game buttons, and the accept one takes the post username as winner, and the post title as loser. I need a way for it to recognize the rating//losses (2 fields in user table) of username (posttitle). I have everything working except this.

Would there be a way to do this without running a query per post?
Reply With Quote
  #4  
Old 01-29-2005, 11:20 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

huh ?
i got you all worng
are you tring to make like vote systen ?
that users will vote who is the winner of the game ?

if you want to use the query you provided (NOT RECOMANED)
here is the syntax :

PHP Code:
if ($thread[threadid] == 1)
{
$gettitle $DB_site->query("SELECT * from ".TABLE_PREFIX."USER where USERNAME='$thread[threadpostername]'");
while (
$postloser $DB_site->fetch_array($gettitle)
{
// do ++++ here
this query will get all users  
}

or if you want to get only 1 user
user

PHP Code:
 $gettitle $DB_site->query_first("SELECT * from ".TABLE_PREFIX."USER where USERNAME='$thread[threadpostername]'"); 
offcurse everything depends on what you want to do
also its might be able that $thread values will be $threadinfo

test on your own risk.
Reply With Quote
  #5  
Old 01-29-2005, 11:30 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, its actually per post not thread, so I need to get it while it does the post queries. --anyone?

What's the difference between using the $DB_site-> and regular mysql_query?
Reply With Quote
  #6  
Old 01-30-2005, 12:03 AM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

form my expriance, if you using more then 1 db table
then its get mixed up - happend to me before

also i think its more safe - not sure..
Reply With Quote
  #7  
Old 01-30-2005, 03:01 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Would having linked tables help here? And could I add the query into this one (if so, how?). I'm really stuck :disappointed:

PHP Code:
        $posts $DB_site->query("
                SELECT
                        post.*, post.username AS postusername, post.ipaddress AS ip,
                        user.*, userfield.*, usertextfield.*,
                        " 
iif($forum['allowicons'], 'icon.title as icontitle, icon.iconpath,') . "
                        " 
iif($vboptions['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.avatardata) AS hascustomavatar, customavatar.dateline AS avatardateline,') . "
                        " 
iif($vboptions['reputationenable'], 'level,') . "
                        " 
iif(!$deljoin'NOT ISNULL(deletionlog.primaryid) AS isdeleted, deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason,') . "
                        editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline,
                        editlog.reason AS edit_reason,

                        post_parsed.pagetext_html, post_parsed.hasimages,
                        IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
                        " 
iif(!can_moderate(), $datastore['hidprofilecache']) . "
                FROM " 
TABLE_PREFIX "post AS post
                LEFT JOIN " 
TABLE_PREFIX "user AS user ON(user.userid = post.userid)
                LEFT JOIN " 
TABLE_PREFIX "userfield AS userfield ON(userfield.userid = user.userid)
                LEFT JOIN " 
TABLE_PREFIX "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
                " 
iif($forum['allowicons'], "LEFT JOIN " TABLE_PREFIX "icon AS icon ON(icon.iconid = post.iconid)") . "
                " 
iif($vboptions['avatarenabled'], "LEFT JOIN " TABLE_PREFIX "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " TABLE_PREFIX "customavatar AS customavatar ON(customavatar.userid = user.userid)") .
                        
iif($vboptions['reputationenable'], " LEFT JOIN " TABLE_PREFIX "reputationlevel AS reputationlevel ON(user.reputationlevelid = reputationlevel.reputationlevelid)") . "
                " 
iif(!$deljoin"LEFT JOIN " TABLE_PREFIX "deletionlog AS deletionlog ON(deletionlog.primaryid = post.postid AND deletionlog.type = 'post')") . "
                LEFT JOIN " 
TABLE_PREFIX "editlog AS editlog ON(editlog.postid = post.postid)
                LEFT JOIN " 
TABLE_PREFIX "post_parsed AS post_parsed ON(post_parsed.postid = post.postid)
                WHERE 
$postids
                ORDER BY dateline 
$postorder 
Sorry if this is against the rules (posting so much of the vb code)
Reply With Quote
  #8  
Old 01-30-2005, 12:52 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by TheSpecialist
Would having linked tables help here? And could Iadd the query into this one (if so, how?). I'm really stuck :disappointed:

PHP Code:
        $posts $DB_site->query("
                SELECT
                        post.*, post.username AS postusername, post.ipaddress AS ip,
                        user.*, userfield.*, usertextfield.*,
                        " 
iif($forum['allowicons'], 'icon.title as icontitle, icon.iconpath,') . "
iif($vboptions['avatarenabled'], 'avatar.avatarpath, NOTISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline,') . "
                        " 
iif($vboptions['reputationenable'], 'level,') . "
iif(!$deljoin'NOT ISNULL(deletionlog.primaryid) AS isdeleted,deletionlog.userid AS del_userid, deletionlog.username AS del_username,deletionlog.reason AS del_reason,') . "
                        editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline,
                        editlog.reason AS edit_reason,

                        post_parsed.pagetext_html, post_parsed.hasimages,
                        IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
                        " 
iif(!can_moderate(), $datastore['hidprofilecache']) . "
                FROM " 
TABLE_PREFIX "post AS post
                LEFT JOIN " 
TABLE_PREFIX "user AS user ON(user.userid = post.userid)
                LEFT JOIN " 
TABLE_PREFIX "userfield AS userfield ON(userfield.userid = user.userid)
                LEFT JOIN " 
TABLE_PREFIX "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
                " 
iif($forum['allowicons'], "LEFT JOIN " TABLE_PREFIX "icon AS icon ON(icon.iconid = post.iconid)") . "
iif($vboptions['avatarenabled'], "LEFT JOIN " TABLE_PREFIX ."avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " .TABLE_PREFIX "customavatar AS customavatar ON(customavatar.userid =user.userid)") .
iif($vboptions['reputationenable'], " LEFT JOIN " TABLE_PREFIX ."reputationlevel AS reputationlevel ON(user.reputationlevelid =reputationlevel.reputationlevelid)") . "
iif(!$deljoin"LEFT JOIN " TABLE_PREFIX "deletionlog ASdeletionlog ON(deletionlog.primaryid = post.postid AND deletionlog.type= 'post')") . "
                LEFT JOIN " 
TABLE_PREFIX "editlog AS editlog ON(editlog.postid = post.postid)
                LEFT JOIN " 
TABLE_PREFIX "post_parsed AS post_parsed ON(post_parsed.postid = post.postid)
                WHERE 
$postids
                ORDER BY dateline 
$postorder 
Sorry if this is against the rules (posting so much of the vb code)


try this 1

PHP Code:
        $posts $DB_site->query("
                SELECT
                        post.*, post.username AS postusername, post.ipaddress AS ip,
                        user.*, userfield.*, usertextfield.*,
                        " 
iif($forum['allowicons'], 'icon.title as icontitle, icon.iconpath,') . "
iif($vboptions['avatarenabled'], 'avatar.avatarpath, NOTISNULL(customavatar.avatardata) AS hascustomavatar,customavatar.dateline AS avatardateline,') . "
                        " 
iif($vboptions['reputationenable'], 'level,') . "
iif(!$deljoin'NOT ISNULL(deletionlog.primaryid) AS isdeleted,deletionlog.userid AS del_userid, deletionlog.username AS del_username,deletionlog.reason AS del_reason,') . "
                        editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline,
                        editlog.reason AS edit_reason,

                        post_parsed.pagetext_html, post_parsed.hasimages,
                        IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
                        " 
iif(!can_moderate(), $datastore['hidprofilecache']) . "
                FROM " 
TABLE_PREFIX "post AS post
                LEFT JOIN " 
TABLE_PREFIX "user AS user ON(user.userid = post.userid)
                LEFT JOIN " 
TABLE_PREFIX "user AS winners ON(user.username = post.username)
                LEFT JOIN " 
TABLE_PREFIX "userfield AS userfield ON(userfield.userid = user.userid)
                LEFT JOIN " 
TABLE_PREFIX "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
                " 
iif($forum['allowicons'], "LEFT JOIN " TABLE_PREFIX "icon AS icon ON(icon.iconid = post.iconid)") . "
iif($vboptions['avatarenabled'], "LEFT JOIN " TABLE_PREFIX ."avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " .TABLE_PREFIX "customavatar AS customavatar ON(customavatar.userid =user.userid)") .
iif($vboptions['reputationenable'], " LEFT JOIN " TABLE_PREFIX ."reputationlevel AS reputationlevel ON(user.reputationlevelid =reputationlevel.reputationlevelid)") . "
iif(!$deljoin"LEFT JOIN " TABLE_PREFIX "deletionlog ASdeletionlog ON(deletionlog.primaryid = post.postid AND deletionlog.type= 'post')") . "
                LEFT JOIN " 
TABLE_PREFIX "editlog AS editlog ON(editlog.postid = post.postid)
                LEFT JOIN " 
TABLE_PREFIX "post_parsed AS post_parsed ON(post_parsed.postid = post.postid)
                WHERE 
$postids
                ORDER BY dateline 
$postorder 
and its will be under winners
i think its should work not sure - not tested.
Reply With Quote
  #9  
Old 01-30-2005, 04:52 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks I think that is what I needed.

Where it says 'user AS winners ON.....' is winners supposed to be the field name, table name, or what. If someone could finish this off for me I would be very happy.

I need the losers rating and loss count (user.losses and user.rating) where the loser = post.title.
Reply With Quote
  #10  
Old 01-30-2005, 04:56 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

filed name is winners
just add 1 more but i dont think you should combined it in this query as you might get info you dont want.
if you want to use the query above then modify it and add the info you need
then check if you get the right values, i dont have time to test it
so you can do it yourself as i showed you the right way to go
if you will have problems please post here again
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 05:13 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.06519 seconds
  • Memory Usage 2,324KB
  • 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)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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