View Full Version : how to make a full PHP and Mysql enabled page
danishravian
05-16-2010, 11:49 AM
i want to make a page at my vbulletin site.
where user may search some data and then i am to display records.
can you please tell me how it can be done ???
see this link to have full idea of my problem.
http://www.haveelskere.dk/page.php?do=2
have a look at that:
http://ragtek.org/blog/vbulletin/vbulletin4-vbulletin/vb-datenbankklasse-benutzen/
danishravian
05-17-2010, 11:19 AM
http://www.haveelskere.dk/page.php?do=2
this is my html page.This form will be submitted to a PHP page which will search data from
database and will diplay data. How It Can Be Done ?
i added this custom page with mod available on this forum to add 5 custom pages on your forum.:erm:
danishravian
05-18-2010, 01:47 PM
i made my custome page by some tutorial posted on this.
now i want to display some data on it through PHP.
all i got till now is that data is currently comming from Template???
can you please tell me where to write my php code??
Lynne
05-18-2010, 01:58 PM
You write your php code in your custom php page.
Why do you keep starting new threads about this same topic? You get replies and then you go start a new thread. Please keep it all in one thread instead of starting another. I've just merged the last three threads you've started about this subject together.
danishravian
05-18-2010, 02:18 PM
You write your php code in your custom php page.
I wrote it there but it is dislpaying my data outside the template.
http://haveelskere.dk/test.php
kindly have a look on it.
Why do you keep starting new threads about this same topic? You get replies and then you go start a new thread. Please keep it all in one thread instead of starting another. I've just merged the last three threads you've started about this subject together.
I made threads but no one replies, thats why i made a new thread !!!! sorry, if it annoys you. but i am not getting something proper. i am playing with my code from 5 days.:(
Lynne
05-18-2010, 02:25 PM
1) Post your code or nobody can tell what you are doing wrong. It looks to me like you are using echo which is not going to put the text where you want it.
2) Sorry, but just because you don't get a response does not mean you should go make another thread about the same thing. People will help if they can. This is an all volunteer run site, so people help out when they have time.
danishravian
05-18-2010, 02:27 PM
this is my code
include "connect.php";
$query = "select * from plants";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$templater->register('query', $query);
$templater->register('result', $result);
$templater->register('row', $row);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo "data found";
}
}
else
{
echo "No Record With These Parameters";
}
Lynne
05-18-2010, 02:39 PM
If you are making a custom page, then you should be following a tutorial such as this one - [HOW TO - vB4] Create your own vBulletin page (https://vborg.vbsupport.ru/showthread.php?t=228112). The above cannot be all of your code, because I can see it is in a vbulletin like page, so there much have been more to it than what you posted. You should post your page/php in php tags and then post your templates in html tags so that it is easier for us to read.
danishravian
05-18-2010, 02:54 PM
I made my page in same way...
only problem i am getting is that
"Data Is being Displayed Outside Template"
http://haveelskere.dk/test.php
please have a look at this link.
Lynne
05-18-2010, 03:00 PM
I've seen the link. I have seen no template code posted from you. You cannot use echo statements if you want to put text inside a vbulletin like page.
borbole
05-18-2010, 03:01 PM
@danishravian, as adviced above, post here the whole codes that make up your test.php file and your custom template. So we can have a clear and full look.
danishravian
05-18-2010, 03:09 PM
I made a template by name TEST using this:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header
$navbar
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">Title</td>
</tr>
<tr>
<td class="alt1">Text</td>
</tr>
</table>
$footer
</body>
</html>
Then i made a TEST.php page which contains
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test'); // change this depending on your filename
// ################### 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(
'TEST',
);
// pre-cache templates used by specific actions
$actiontemplates = array(
);
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
include "connect.php";
$query = "select * from plants";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$templater->register('query', $query);
$templater->register('result', $result);
$templater->register('row', $row);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo "data found";
}
}
else
{
echo "No Record With These Parameters";
}
// ################################################## #####################
$navbits = construct_navbits(array('' => $vbulletin->options['TEST']));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = $vbulletin->options['TEST'];
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('TEST');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $vbulletin->options['TEST']);
print_output($templater->render());
?>
Problem is same that loop is displaying data outside the template as in this link
http://www.haveelskere.dk/test.php
borbole
05-18-2010, 03:22 PM
I made a template by name TEST using this:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header
$navbar
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">Title</td>
</tr>
<tr>
<td class="alt1">Text</td>
</tr>
</table>
$footer
</body>
</html>
Then i made a TEST.php page which contains
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test'); // change this depending on your filename
// ################### 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(
'TEST',
);
// pre-cache templates used by specific actions
$actiontemplates = array(
);
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
include "connect.php";
$query = "select * from plants";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$templater->register('query', $query);
$templater->register('result', $result);
$templater->register('row', $row);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo "data found";
}
}
else
{
echo "No Record With These Parameters";
}
// ################################################## #####################
$navbits = construct_navbits(array('' => $vbulletin->options['TEST']));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = $vbulletin->options['TEST'];
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('TEST');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $vbulletin->options['TEST']);
print_output($templater->render());
?>
Problem is same that loop is displaying data outside the template as in this link
http://www.haveelskere.dk/test.php
Your template is all wrong. Try to create a correct one for vb 4x by using the example at this tutorial.
https://vborg.vbsupport.ru/showthread.php?t=228112
danishravian
05-18-2010, 04:05 PM
I did all (updated my work), but still same problem :(
http://www.haveelskere.dk/test.php
cellarius
05-18-2010, 04:41 PM
You need to take the time and try to understand what happens in the code.
1. You can not use echo, as Lynne already told you. That's what makes the results show up on top of the pages. You need to save the output of the loop into a variable, and that variable needs to be registered for use in your template. Replace echo with
$output =
// or, since we're in a loop,
$output .=2. Get your php code in order. There is a good cause for the comment "Your custom code goes here". Why don't you put your custom code there, but somewhere above? That's all messy!
3. There's no sense in wildly registering variables like $query, $row and $result in the middle of nowhere. Those three variables are only used in your php code, so there is no need to register them. Registering variables is for passing variables from the php code to the template. This happens under the comment "Now your template is being rendered." Add a line like this
$templater->register('output', $output); where some other variables are being registered already and call it in the template using
{vb:raw output}
danishravian
05-19-2010, 12:46 PM
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'test');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### 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('TEST',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = construct_navbits(array('' => 'Test Page'));
$navbar = render_navbar_template($navbits);
$code = "<div style='font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
font-weight: bold;
padding-left:30px;' >Sun flower</div>
<div style='width:106px;
height:109px;
margin-left:20px;
float:left;'><img src='images/flower_03.png' style='float:left' /></div>
<div style='height:150px;
width:338px;
float:left;'><div style='font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 19px;
font-weight: normal;
padding-left:6px;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vulputate, nibh eget ehiculaolestie, augue mi eleifend eros, fermentuaculis agna diam sed mi. Fusce euismodtortor at Fusce euismodtortor at</div> </div>
<div><div style='height:150px;
width:109px;
float:left;'><img src='images/Untitled-1.png' /><br />PlantsBlooms<br />Size<br />Light</div></div>
<div style='float:left;'>
4.5/5<br />
May - June<br />
May - June<br />
May - June<br /></div>
</div>
<div style='width:687;
height:142px;
padding-top:13px;
border:ridge;
border-width:2px;
border-color:cddee9;
margin-top:10px;'>";
include "connect.php";
$result = $db->query_read("SELECT * from plants");
$resultset = $db->fetch_array($result);
while ($userdata = $db->fetch_array($result))
{
// nun stehen die Daten in $userdata zur Verf?gung
echo $userdata['id'];
}
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'My Page Title';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('TEST');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('code', $code);
print_output($templater->render());
?>
i have registered my variable $code in template and its working OK.
if i use this code to display data, it displays it outside the template :(
but i have to display all records from database.
how it can be done?? any clue:confused:
$result = vB::$vbulletin->db->query_read("SELECT * from plants");
$resultset = vB::$vbulletin->db->fetch_array($result);
while ($userdata = vB::$vbulletin->db->fetch_array($result))
{
// nun stehen die Daten in $userdata zur Verf?gung
echo $userdata['id'];
}
First I was using this code to get and dislpay data. But it was dislplaying error message that "VB class not found"
--------------- Added 1274277151 at 1274277151 ---------------
cellarius thnxxxxx a lottttttt a got some Idea:)
you are sooo goood :)
cellarius
05-19-2010, 02:04 PM
For everyone else interested: The problem most likely was that there still was an echo statement in the php code.
Glad you figured it out :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.