vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How to use query result in same php file (https://vborg.vbsupport.ru/showthread.php?t=206388)

NeverBored 02-23-2009 10:26 PM

How to use query result in same php file
 
I have this query

Code:

        $ytvideo = $db->query_read("SELECT threadid FROM thread WHERE ytvideo = '$id'");

        if($row = $db->fetch_array($ytvideo)) {
                $ytvideoid = $row[threadid];
        }

Which does what I want, this php file outputs to vb templates and I currently use $ytvideoid to do a javascript include, but I want to do the include in php. So how do I use $ytvideoid inside the php file? When I try to use it in the the file it has no value.

Thanks

TigerC10 02-23-2009 10:30 PM

That's what the plugin system is for. You can use plugin hooks to call code like that from the PHP files. Open the .PHP file you want to include it in, and find a hook location for it.

NeverBored 02-23-2009 11:01 PM

The php file I'm working in isn't a vbulletin file. It's a project I'm working on integrated with vb. I just want to figure out how to use $ytvideoid from the code above in the file rather than in the template. Using it in the file right now it has no value, but in the template it has the correct value...

TigerC10 02-24-2009 01:02 AM

Then I would say the reason the variable doesn't have any value is because the variable $id isn't defined in your PHP file. You'll want to try to find a different variable for it, because that's probably defined by whatever's calling the template.

Next, your select statement isn't cool, you should do this:
Code:

"SELECT threadid FROM ".TABLE_PREFIX."thread WHERE
That way if you ever do set up on a board with a prefix you won't end up with a broken self-made mod.

Dismounted 02-24-2009 04:04 AM

PHP Code:

// query data
$ytvideo $vbulletin->db->query_first("
    SELECT threadid
    FROM " 
THREAD_PREFIX "thread
    WHERE ytvideo = 
$id
    LIMIT 1
"
);

// spit id
echo $ytvideo['threadid']; 



All times are GMT. The time now is 03:38 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.01013 seconds
  • Memory Usage 1,718KB
  • 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
  • (2)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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