FUEL Posted February 23, 2010 Share Posted February 23, 2010 Hi all i just started out with .php and made a few pages however im having trouble with the following page: Question: how do i display the search below to a template file?? Ok first ill describe what im making: Its an simple overview of a table of my database. On a game site i want to create an overview of match results submitted by players. The war_overview.php file has the sql query: <?php //session database etc etc $dbc = mysqli_connect('***'); //replay upload path define('REPLAY_UPLOAD_PATH', $phpbb_root_path . 'replays/'); $query = 'SELECT * FROM ' . war_matches . ' ORDER BY match_id ASC'; $result = mysqli_query($dbc, $query); // loop through array display as html print '<table>'; while ($row = mysqli_fetch_array($result)) { // display the database print '<tr>'; if ($row['human_score'] == 0 ) { print '<td class="alien_win">'; } else { print '<td class="human_win">'; } print '<strong>Game Number: </strong>' . $row['game_number'] . ', '; if ($row['alien_score'] == 0 ) { print '<strong>Score Humans: + </strong>' . $row['human_score'] . '<br />'; } else { print '<strong>Score Aliens: + </strong>' . $row['alien_score'] . '<br />'; } print '<strong>Winner: </strong>'. $row['rank_winner'] . $row['name_winner'] . ', '; print '<strong>Winner Strength: </strong>' . $row['group_winner'] . '<br />'; print '<strong>Loser: </strong>' . $row['rank_loser'] . $row['name_loser'] . ', '; print '<strong>loser Strenght: </strong>' . $row['group_loser'] . '<br />'; print '<strong>Claimed at: </strong>' . $row['claim_time'] . ' '; print '<strong>War Phase: </strong>' . $row['war_phase'] . ' '; if (is_file(REPLAY_UPLOAD_PATH . $row['replay']) && filesize(REPLAY_UPLOAD_PATH . $row['replay']) > 0) { print '<td><a href="' . REPLAY_UPLOAD_PATH . $row['replay'] .'"><img src="/phpBB3/styles/7kplay/theme/images/downloadreplay.png" alt="Download replay" /></a></td></tr>'; } else { print '<td>No replay uploaded</td><tr>'; } } print '</table>'; mysqli_close($dbc); now i want this to display on a template file: /otherlocation/battle results.html how must i rebuild this php file to be sending this to the battle results.html file? I tried a lot but the furthest i got was displaying all on the template fil above the headers Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/ Share on other sites More sharing options...
aeroswat Posted February 23, 2010 Share Posted February 23, 2010 Hi all i just started out with .php and made a few pages however im having trouble with the following page: Question: how do i display the search below to a template file?? Ok first ill describe what im making: Its an simple overview of a table of my database. On a game site i want to create an overview of match results submitted by players. The war_overview.php file has the sql query: <?php //session database etc etc $dbc = mysqli_connect('***'); //replay upload path define('REPLAY_UPLOAD_PATH', $phpbb_root_path . 'replays/'); $query = 'SELECT * FROM ' . war_matches . ' ORDER BY match_id ASC'; $result = mysqli_query($dbc, $query); // loop through array display as html print '<table>'; while ($row = mysqli_fetch_array($result)) { // display the database print '<tr>'; if ($row['human_score'] == 0 ) { print '<td class="alien_win">'; } else { print '<td class="human_win">'; } print '<strong>Game Number: </strong>' . $row['game_number'] . ', '; if ($row['alien_score'] == 0 ) { print '<strong>Score Humans: + </strong>' . $row['human_score'] . '<br />'; } else { print '<strong>Score Aliens: + </strong>' . $row['alien_score'] . '<br />'; } print '<strong>Winner: </strong>'. $row['rank_winner'] . $row['name_winner'] . ', '; print '<strong>Winner Strength: </strong>' . $row['group_winner'] . '<br />'; print '<strong>Loser: </strong>' . $row['rank_loser'] . $row['name_loser'] . ', '; print '<strong>loser Strenght: </strong>' . $row['group_loser'] . '<br />'; print '<strong>Claimed at: </strong>' . $row['claim_time'] . ' '; print '<strong>War Phase: </strong>' . $row['war_phase'] . ' '; if (is_file(REPLAY_UPLOAD_PATH . $row['replay']) && filesize(REPLAY_UPLOAD_PATH . $row['replay']) > 0) { print '<td><a href="' . REPLAY_UPLOAD_PATH . $row['replay'] .'"><img src="/phpBB3/styles/7kplay/theme/images/downloadreplay.png" alt="Download replay" /></a></td></tr>'; } else { print '<td>No replay uploaded</td><tr>'; } } print '</table>'; mysqli_close($dbc); now i want this to display on a template file: /otherlocation/battle results.html how must i rebuild this php file to be sending this to the battle results.html file? I tried a lot but the furthest i got was displaying all on the template fil above the headers Sorry are you just trying to include this php file in the html file? If so rename the battle results html to battle results php and use the following in that file wherever you want it to show up <?php include 'war_overview.php'; ?> Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/#findComment-1016974 Share on other sites More sharing options...
FUEL Posted February 23, 2010 Author Share Posted February 23, 2010 no this is a part of an .php file, the structure cant be changed because then my headers, and the rest of the info on the page won't work. i want it to work with the template file which has to stay html. somehow i have to make the results of the query go into a $variable so that i can send it to the template with this command // Output page page_header($user->lang['OVERVIEW']); $template->set_filenames(array( 'body' => 'battle_results.php') ); page_footer(); when i use variables however, i can only get the last result in there. Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/#findComment-1016989 Share on other sites More sharing options...
aeroswat Posted February 23, 2010 Share Posted February 23, 2010 no this is a part of an .php file, the structure cant be changed because then my headers, and the rest of the info on the page won't work. i want it to work with the template file which has to stay html. somehow i have to make the results of the query go into a $variable so that i can send it to the template with this command // Output page page_header($user->lang['OVERVIEW']); $template->set_filenames(array( 'body' => 'battle_results.php') ); page_footer(); when i use variables however, i can only get the last result in there. Load the result of the query into an array? $arr = array(); $result = mysql_query("Your qry") while($row = mysql_fetch_assoc($result)) { $arr[] = $row; } Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/#findComment-1016996 Share on other sites More sharing options...
FUEL Posted February 23, 2010 Author Share Posted February 23, 2010 yes that could work!, is it possible to declare the results an array? how do i use that so it displays all the results not just the last? Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/#findComment-1017006 Share on other sites More sharing options...
aeroswat Posted February 23, 2010 Share Posted February 23, 2010 yes that could work!, is it possible to declare the results an array? how do i use that so it displays all the results not just the last? That will display all the results. You can access them just like any other array. Best way if you need to go through them again is to use a foreach foreach($arr as $r) { echo $r['column_name']; } Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/#findComment-1017011 Share on other sites More sharing options...
FUEL Posted February 24, 2010 Author Share Posted February 24, 2010 It still isnt working. So ive changed to set the data to an array but still i cant display the results on my template file. Here's the war_overview.php /// Scores index //replay upload path 7kplay define('REPLAY_UPLOAD_PATH', $phpbb_root_path . 'replays/'); //sql fetch $dbc = mysqli_connect('*****'); $match_result = array(); $query = 'SELECT * FROM ' . war_matches . ' ORDER BY match_id ASC'; $result = mysqli_query($dbc, $query); // loop through array display as html while ($row = mysqli_fetch_assoc($result)) { $match_result[] = $row; } foreach ($match_result as $r) { echo $r['game_number'], "\n", $r['match_id'], !more variables here!"<br />"; } mysqli_close($dbc); // Output page page_header($user->lang['INDEX2']); $template->set_filenames(array( 'body' => 'battle_results.html') ); page_footer(); ?> the will display like I was when i started: the result on top of the site even above the headers. Deleting this out of the .php file and putting it on the .html template file doesnt work. foreach ($match_result as $r) { echo $r['game_number'], "\n", $r['match_id'], !more variables here!"<br />"; } anyone can help me? Link to comment https://forums.phpfreaks.com/topic/193111-php-script-to-template-issue/#findComment-1017181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.