PDA

View Full Version : What am i doing wrong?


Jaynesh
04-09-2006, 09:59 PM
What am i doing wrong here?

Im trying to display all the rows in the table.
But its not working, there is no error message. It just doesnt display!


<?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', 'test');

// #################### 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
'test',
);

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

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

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

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

$userid = $vbulletin->userinfo['userid'];
$usergroupid = $vbulletin->userinfo['usergroupid'];
$username = $vbulletin->userinfo['username'];

function foo()
{
global $vbulletin;

$views = $db->query_first("SELECT * FROM test");
while ($view = $vbulletin->db->fetch_array($views))
{
}
$vbulletin->db->free_result($views);
}


$navbits = array();
$navbits[$parent] = 'Test Page';

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


?>

Code Monkey
04-09-2006, 10:05 PM
You have nothing in your while loop which means no output to display.

Plus, I don't see where you are even using the function named foo.

Jaynesh
04-09-2006, 10:11 PM
You have nothing in your while loop which means no output to display.

Plus, I don't see where you are even using the function named foo.

I got it from here https://vborg.vbsupport.ru/showthread.php?t=106053

Could you tell me how to fix it or do it the correct way? Im new to php :confused:

Code Monkey
04-09-2006, 10:15 PM
<?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', 'test');

// #################### 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
'test',
);

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

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

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

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

$userid = $vbulletin->userinfo['userid'];
$usergroupid = $vbulletin->userinfo['usergroupid'];
$username = $vbulletin->userinfo['username'];

$views = $db->query_first("SELECT * FROM test");
while ($view = $vbulletin->db->fetch_array($views))
{
echo $view['some_collumn_name'];
}
$vbulletin->db->free_result($views);



$navbits = array();
$navbits[$parent] = 'Test Page';

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

?>

Jaynesh
04-09-2006, 10:21 PM
Im getting a parse error.

Parse error: parse error, expecting `','' or `';'' in c:\program files\easyphp1-8\www\test.php on line 44

Okay i fixed the parse error but it still is not displaying rows. No errors.

Okay okay i got it :D Thanks alot :D

Code Monkey
04-09-2006, 10:57 PM
Yeah, you need to use actual database collumn names.

Jaynesh
04-09-2006, 11:03 PM
Lol yep ive got it.

Ive now put $view[column] in the template.
But it only displays the first row.
How can i display all rows?


<?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', 'test');

// #################### 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
'test',
);

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

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

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

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

$userid = $vbulletin->userinfo['userid'];
$usergroupid = $vbulletin->userinfo['usergroupid'];
$username = $vbulletin->userinfo['username'];

$views = $db->query_read("SELECT * FROM test");
while ($view = $vbulletin->db->fetch_array($views))
{
$review = $view['review'];
$member = $view['member'];

$vbulletin->db->free_result($views);

$navbits = array();
$navbits[$parent] = 'Test Page';

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

?>

Code Monkey
04-09-2006, 11:09 PM
You don't want all these in that loop.


$vbulletin->db->free_result($views);

$navbits = array();
$navbits[$parent] = 'Test Page';

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

Jaynesh
04-10-2006, 07:01 AM
It still only displays one row?

If i do this


{
echo $view['review'];
echo $view['member'];

}


It displays all the rows.

but if i do this and try and put it in the template file it only displays one row.


{
$review = $view['review'];
$member = $view['member'];

}

Code Monkey
04-10-2006, 01:18 PM
You need a template file for the rows (inside the loop) then a main template to hold the rows (outside the loop).


$views = $db->query_first("SELECT * FROM test");
$viewrow = '';
while ($view = $vbulletin->db->fetch_array($views))
{
$review = $view['review'];
$member = $view['member'];
eval('$viewrow .= "' . fetch_template('viewrows') . '";');
}
eval('$viewtable = "' . fetch_template('viewtable') . '";');
$vbulletin->db->free_result($views);
$navbits = array();
$navbits[$parent] = 'Test Page';

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

Jaynesh
04-29-2006, 11:50 AM
So i must create another template called viewrows and viewtable?

What has to go in there?

Is there any other way?