[HELP]How to use PHP scipt in vb

AOL

New Member
Hello everybody, I'm using vb version 3.8
I wrote a tiny php script to query my vb database:

Code:
$query = "SELECT * FROM user WHERE id=10";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
    {
        $tmp = $row['username'];
    }

(example.php)

And now i want to use $tmp variable to insert into footer template.

Please help me. Thank you very much !
 

bluescorpion

New Member
vBulletin can execute PHP directly but only in a plugin BUT the php code you are trying to execute has a fatal flaw, it has no database connection because vbulletin has set itself up with its own set of mnemonics that you are not using in your call.

Create a new plugin:

Product vbulletin
Hook Location global_start
Title Call it what ever you like
Execution Order 5
Plugin PHP Code

PHP:
$getuser = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "`user` WHERE `userid`>='10'");
    
    $numRows = $vbulletin->db->fetch_row($getuser);
    
    $founduser = $numRows[4];

This code generates the username as per your example with a different query, yours will work as well if you integrate it into this code. It just happens to be a query that I frequently use.

In this model, where ever you place $founduser, it will display the name of the user. You can adapt this to fix your code but $tmp will probably have problems as it is quite likely being used elsewhere in the code.

BTW, it is very useful to "study" the code of other plugins that you may have installed on your system to see how things go together in vBulletin.
 

AOL

New Member
Oh, i got it. Thank you very much.

And now I want to generate an array that is a list of userid. This list contains 10 random userids. How can i do that. Please help me. Thanks again !
 

bluescorpion

New Member
See if this helps:

Retrieving a single row:
$result = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "table WHERE rowid = 1");
$result will contain an array with all columns of the retrieved table row.

Retrieving multiple rows:
// Prepair the query
$result_set = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "table");
// Loop through all results:
while ($result = $vbulletin->db->fetch_array($result_set))
do
{
// $result will contain 1 fetched row here
....process data.... (you could load an array here)
}


I would get the query to do the random select work if I were doing it.
 
Top