PDA

View Full Version : How to use query result in same php file


NeverBored
02-23-2009, 10:26 PM
I have this query

$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:

"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
// query data
$ytvideo = $vbulletin->db->query_first("
SELECT threadid
FROM " . THREAD_PREFIX . "thread
WHERE ytvideo = $id
LIMIT 1
");

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