Is there anything wrong with this script?

Discussion in 'PHP' started by egdcltd, Aug 8, 2006.

  1. #1
    I am having problems getting some php to work, and I don't know if the problem is with the sql and php, or with the template I'm using to display the output. Is there anything wrong with the following?

    $sql = "SELECT character_name , character_class , character_level FROM phpbb_adr_characters WHERE character_hp <= '0'";
    if( !($result = $db->sql_query($sql)) )
    {
    	message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
    }
    
    if ( $row = $db->sql_fetchrow($result) )
    {
    	$i = 0;
    	do
    	{
    			$template->assign_block_vars('secondcharacters', array(
    			"SECONDCHARACTER_NAME" => $row['character_name'],
    			"SECONDCHARACTER_LEVEL" => $row['character_level'],
    			"SECONDCHARACTER_CLASS" => $row['character_class'],
    		));
    
    		$i++;
    	}
    	while ( $row = $db->sql_fetchrow($result) );
    
    }
    PHP:
     
    egdcltd, Aug 8, 2006 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    Well, it'd be more helpful if you could explain what the problem is
     
    BRUm, Aug 8, 2006 IP
  3. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm trying to get information from the database, then, using a template file, display that information, or at least selected parts of it. Nothing is showing up, however.
     
    egdcltd, Aug 8, 2006 IP
  4. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Post the complete code please. Then we will be able to help you better. Are you using the Smarty template system? Make sure you call :

    
    $smarty->display('index.tpl');// change index.tpl to your template filename
    
    PHP:
    to display the template.

    Thomas
     
    coderlinks, Aug 8, 2006 IP
  5. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No, it's using phpBB.

    The entire code for the page is:
    
    <?php
    define('IN_PHPBB', true);
    define('IN_ADR_ZONES', true);
    define('IN_ADR_CHARACTER', true);
    define('IN_ADR_GRAVEYARD', true);
    $phpbb_root_path = './';
    include_once($phpbb_root_path . 'extension.inc');
    include_once($phpbb_root_path . 'common.'.$phpEx);
    
    //
    // Start session management
    $userdata = session_pagestart($user_ip, PAGE_INDEX);
    init_userprefs($userdata);
    // End session management
    //
    $user_id = $userdata['user_id'];
    include_once($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
    
    // Sorry , only logged users ...
    if ( !$userdata['session_logged_in'] )
    {
    	$redirect = "adr_character.$phpEx";
    	$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
    	header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
    }
    
    // Includes the tpl and the header
    adr_template_file('adr_graveyard_body.tpl');
    include_once($phpbb_root_path . 'includes/page_header.'.$phpEx);
    
    // Get the general config and character infos
    $adr_general = adr_get_general_config();
    adr_enable_check();
    adr_ban_check($user_id);
    $adr_user = adr_get_user_infos($user_id);
    
    
    
    
    
    //Select from character table
    $sql = "SELECT character_name , character_class , character_level FROM " . ADR_CHARACTERS_TABLE . " WHERE character_hp <= '0'";
    if( !($result = $db->sql_query($sql)) )
    {
    	message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
    }
    
    if ( $row = $db->sql_fetchrow($result) )
    {
    	$i = 0;
    	do
    	{
    			$template->assign_block_vars('secondcharacters', array(
    			"SECONDCHARACTER_NAME" => $row['character_name'],
    			"SECONDCHARACTER_LEVEL" => $row['character_level'],
    			"SECONDCHARACTER_CLASS" => $row['character_class'],
    		));
    
    		$i++;
    	}
    	while ( $row = $db->sql_fetchrow($result) );
    
    }
    
    $template->assign_vars(array(
    	'L_CHARACTER_NAME' => $lang['Adr_character'],
    	'L_LEVEL' => $lang['Adr_character_level'],
    
    
    ));
    
    include($phpbb_root_path . 'adr/includes/adr_header.'.$phpEx);
    
    $template->pparse('body');
    include_once($phpbb_root_path . 'includes/page_tail.'.$phpEx);
    
    ?>
    PHP:
    The template is displaying okay, except the data I'm calling isn't displaying.
     
    egdcltd, Aug 8, 2006 IP
  6. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    One of the easiest ways to troubleshoot is to start throwing some echos in there (sure, it can look ugly from the template, but that's not really your concern at the moment). At each point add echo "Got to X<br />"; replacing X with an integer or letter. Then, you can see approximately where you are running into trouble (such as if a loop isn't being called). As you get closer to the problem, you can echo the variables related to that section of the code, so you can see if some aren't being set correctly.
     
    Gordaen, Aug 8, 2006 IP
  7. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks. Looks like the problem is in the template.
     
    egdcltd, Aug 8, 2006 IP