Log in

View Full Version : Creating Custom Pages


aragorn_reborn
12-01-2006, 09:34 AM
Hi,

Where can i get tutorials for "Creating Custom Pages that query the database"? I have read

How to create your own vBulletin-powered page! (uses vB templates) at https://vborg.vbsupport.ru/showthread.php?t=62164&page=32

I have also read about the database classes.

As i understand now, i have to do the coding part in the php file and create a template to display the data. How do i pass data obtained from the database to the template.

If there is any guide/tutorial for the same, please give me the link. If there isnt please give me some pointers

Thanks in advance

aragorn_reborn
12-02-2006, 10:32 AM
So, Noone replied!! I guess i have asked a very broad question..

Let me start with a narrower one

Suppose i make a file test.php and retrive some values from a database. Now, i want to display those values. How exactly do i go about doing so?

I mean the values will be displayed in the templates and the retrieve done in the php, so how does one go about passing values to the template.

I hope i explained my query properly.

Thanks in advance

~M

wottech
12-02-2006, 04:01 PM
Here is a section of code from one of my pages that should help you out. I'm not sure I can explain it all, but I know it works.

if ($_REQUEST['do'] == 'Calculate with Own Data')
{
$eng=$_POST["engine"];
$overbore=$_POST["overbore"];
$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die
('Error connecting to mysql');
mysql_select_db($dbname);

$result = mysql_query("SELECT * FROM cr_calc_data WHERE engine = $eng");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;

}
$row = mysql_fetch_row($result);
mysql_close($conn);
$engine=$row[8];
$bore = $row[1]+$overbore;
$navbits = array();
$navbits[$parent] = 'CR Calculator - Default Values';

$navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('CRCALC2') . '");');
}


The parts to look at are the POST command and then the EVAL command at the very end where it calls the template. I'll try to help you out where I can, but I'm only a novice coder. It took many tries before I got it all to work correctly.

aragorn_reborn
12-04-2006, 03:41 PM
Thanks tht helped.

I am facing a problem now with scripts placed outside the vbulletin directory

See

http://www.genportal.org/team/team_builder.php

The forum is located at genportal.org/forum/

The images and the links do not work because they dont get the right path...

Here is the code i have used. What have i done wrong

<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT', 'team_builder');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
// change the lines below to the list of actual templates used in the script
'team_builder',
'team_builder2',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
chdir('../forum');
require_once('./global.php');
if (!$vbulletin->userinfo['userid'])
{
print_no_permission();
}

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

$navbits = array();
// change the line below to contain whatever you want to show in the navbar (title of your custom page)
$navbits[$parent] = 'Team Builder';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

$hello = "Hello World";

// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('team_builder') . '");');

?>

peterska2
12-04-2006, 04:05 PM
Change your links in your header, footer and navbar templates to full links.

Change your image paths to full URL's.

This happens with anything that is not in the same directory.

aragorn_reborn
12-05-2006, 06:25 PM
Wht about CSS?

The pages dont get the CSS as well

Where is $style[css] defined?

peterska2
12-05-2006, 06:40 PM
Try using the CSS in the db instead of the filesystem

aragorn_reborn
12-05-2006, 06:47 PM
How does one do that? Please explain

I havent changed anything. Is the default CSS from the file or from the database

peterska2
12-05-2006, 06:50 PM
It seems to be working ok here with the default style. Is it the default style or another one that you are having problems with?

BTW, your CSS is stored in the db already.

aragorn_reborn
12-05-2006, 08:46 PM
Thanks

How do i get IP and username of the person on my page??

aragorn_reborn
12-07-2006, 03:48 AM
okay username can be obtained by $vbulletin->userinfo[username]

How do i get IP??

michaelsilvia
12-07-2006, 10:12 AM
Why are you wasting your time with this? Their is a WebTemplates hack that allows you to create custom pages with dozens of options. I create pages in seconds using HTML, BB Code or text.