Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Adding queries the "right way" Details »»
Adding queries the "right way"
Version: , by zonegray zonegray is offline
Developer Last Online: Aug 2003 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 11-17-2002 Last Update: Never Installs: 0
 
No support by the author.

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)'];
The included file "msfdev" simply includes the connection information:
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());
?>
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.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 11-17-2002, 02:42 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

try this:

PHP Code:
<?php
require('global.php');

mysql_select_db($database_msfdev$msfdev);
$query_Recordset1 "SELECT MAX(lastpost) FROM forum WHERE newsforum = 1 ";
$Recordset1 $DB_site->query($query_Recordset1);
$row_Recordset1 $DB_site->fetch_array($Recordset1);
$totalRows_Recordset1 $DB_site->num_rows($Recordset1);
$lastupdate=$row_Recordset1['MAX(lastpost)'];
that should be what you wanted.
Reply With Quote
  #3  
Old 11-17-2002, 04:47 PM
zonegray zonegray is offline
 
Join Date: Feb 2002
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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);
Those variables are defined in the Dreamweaver connection file. Are there some variables defined in global.php that I can substitute in the mysql_select_db statement?
Reply With Quote
  #4  
Old 11-17-2002, 05:05 PM
zonegray zonegray is offline
 
Join Date: Feb 2002
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 11-18-2002, 04:11 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're welcome

the DB_site objects can be found in db_mysql.php in your admin directory
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:58 PM.


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.03768 seconds
  • Memory Usage 2,240KB
  • Queries Executed 18 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete