The Arcive of vBulletin Modifications Site. |
|
Adding queries the "right way" Details »»
|
|||||||||||||||||||||||||
I'm building a new front page (/index.php), and I need to understand the "right way" to add queries.
I include global.php, and have access to all my templates, etc. and it works fine. Now I want to add a query. Since I know just enough PHP to be dangerous, I first tried it using Dreamweaver MX. And it works, but I'm obviously opening an extra database connection, including files that I shouldn't etc. Here's what Dreamweaver created: Code:
<?php require_once('Connections/msfdev.php'); ?>
<?php
mysql_select_db($database_msfdev, $msfdev);
$query_Recordset1 = "SELECT MAX(lastpost) FROM forum WHERE newsforum = 1 ";
$Recordset1 = mysql_query($query_Recordset1, $msfdev) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$lastupdate=$row_Recordset1['MAX(lastpost)'];
Code:
<?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_msfdev = "localhost"; $database_msfdev = "dbname"; $username_msfdev = "dbuser"; $password_msfdev = "password"; $msfdev = mysql_pconnect($hostname_msfdev, $username_msfdev, $password_msfdev) or die(mysql_error()); ?> BTW, the particular query I'm doing selects the timestamp of the newest thread in my news forums, which are denoted by a field that I added to the db (newsforum="1"). As I said, it works fine as is, but I know that it's sloppy programming. Show Your Support
|
|||||||||||||||||||||||||
| Comments |
|
#2
|
||||
|
||||
|
try this:
PHP Code:
|
|
#3
|
|||
|
|||
|
Thanks... that's exactly what I'm after, but it only "almost" works.
Problem is with the line: Code:
mysql_select_db($database_msfdev, $msfdev); |
|
#4
|
|||
|
|||
|
Duh... RTFM, read the function description, deleted the line, and now it works.
Thanks. I've been looking for how to do this, couldn't find many refs with a search. I tried to figure out the $DB_site object, but wasn't having any luck. From the looks of it, I can just call it from anywhere, and it'll derive the connection info from vB. |
|
#5
|
||||
|
||||
|
You're welcome
![]() the DB_site objects can be found in db_mysql.php in your admin directory |
![]() |
|
|