zonegray
11-17-2002, 01:31 PM
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:<?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)'];
The included file "msfdev" simply includes the connection information:<?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());
?>How can I rewrite this more efficiently, using the config info from vBulletin and/or any functions available via global.php?
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.
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:<?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)'];
The included file "msfdev" simply includes the connection information:<?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());
?>How can I rewrite this more efficiently, using the config info from vBulletin and/or any functions available via global.php?
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.