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:
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.
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
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.
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.