malma Posted March 3, 2015 Share Posted March 3, 2015 I think now i'm becoming a familier with asking endlessly but please don't get tired of me. Right now i'm having another problem; I am to make the pages content from database appear on my localhost website but I don't know if i'm making mistakes somewhere. Please take a look on my codes. >>>>>>>>CONTENT AREA>>>>>>>>>>> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php find_selected_page(); ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <?php echo navigation($sel_subject, $sel_page); ?> <br/> <a href="new_subject.php">+ Add a new subject</a> </td> <td id="page"> <?php if (!is_null($sel_subject)) {//subject selected ?> <h2><?php echo $sel_subject['menu_name']; ?></h2> <?php } elseif (!is_null($sel_page)) { // page selected ?> <h2><?php echo $sel_page['menu_name']; ?></h2> <div class="page-content"> <?php echo $sel_page['content']; ?> </div> <?php } else { // nothing selected ?> <h2>Select a subject or page edit</h2> <?php }?> </td> </tr> </table> <?php require("includes/footer.php"); ?> >>>>>>>>>FUNCTION<<<<<<<<<<<< function get_pages_for_subject($subject_id){ global $connection; $query = "SELECT * FROM pages WHERE subject_id = ($subject_id ) ORDER BY position ASC"; $page_set = mysqli_query( $connection, $query); confirm_query($page_set); return $page_set; } function get_subject_by_id($subject_id) { global $connection; $query = " SELECT * "; $query .= " FROM subjects "; $query .= " WHERE id=" . $subject_id ." "; $query .= " LIMIT 1"; $result_set = mysqli_query($connection, $query); confirm_query($result_set); if($subject = mysqli_fetch_array($result_set)){ return $subject; }else { return NULL; } } function get_page_by_id($page_id) { global $connection; $query = " SELECT * "; $query .= " FROM pages "; $query .= " WHERE id=" . $page_id ." "; $query .= " LIMIT 1"; $result_set = mysqli_query($connection, $query); confirm_query($result_set); //REMEMBER: // if no rows are returned, fetch_array will return false //** return $page;** on line 58 was bring error instead if($subject = mysqli_fetch_array($result_set)){ }else { return NULL; } } function find_selected_page(){ global $sel_subject; global $sel_page; if (isset($_GET['subj'])) { $sel_subject = get_subject_by_id($_GET['subj']); $sel_page = NULL; } elseif (isset($_GET['page'])) { $sel_subject = NULL; $sel_page = get_page_by_id($_GET['page']); } else { $sel_subject = NULL; $sel_page = NULL; } } The underlined <div class="page-content> is not working, maybe I mased up my codes somewhere. Thanks for your help..... Quote Link to comment Share on other sites More sharing options...
joel24 Posted March 3, 2015 Share Posted March 3, 2015 put some debugging in there to see if you reach that block as you've got a few if conditions prior <div class="page-content"> <?php echo "<h1>IN HERE</h1><pre>".print_r($sel_page,1); ?> </div> Quote Link to comment Share on other sites More sharing options...
malma Posted March 4, 2015 Author Share Posted March 4, 2015 Thank you so much Joel24 for your advice but still not working, I just copped and paste the all php code as you wrote it. Quote Link to comment Share on other sites More sharing options...
laflair13 Posted March 4, 2015 Share Posted March 4, 2015 (edited) Although I am very new to php, I did notice you didnt wrap the function in <?php FUNCTION CODE ?> here is the code with it >>>>>>>>CONTENT AREA>>>>>>>>>>> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php find_selected_page(); ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <?php echo navigation($sel_subject, $sel_page); ?> <br/> <a href="new_subject.php">+ Add a new subject</a> </td> <td id="page"> <?php if (!is_null($sel_subject)) {//subject selected ?> <h2><?php echo $sel_subject['menu_name']; ?></h2> <?php } elseif (!is_null($sel_page)) { // page selected ?> <h2><?php echo $sel_page['menu_name']; ?></h2> <div class="page-content"> <?php echo $sel_page['content']; ?> </div> <?php } else { // nothing selected ?> <h2>Select a subject or page edit</h2> <?php }?> </td> </tr> </table> <?php require("includes/footer.php"); ?> >>>>>>>>>FUNCTION<<<<<<<<<<<< <?php function get_pages_for_subject($subject_id){ global $connection; $query = "SELECT * FROM pages WHERE subject_id = ($subject_id ) ORDER BY position ASC"; $page_set = mysqli_query( $connection, $query); confirm_query($page_set); return $page_set; } function get_subject_by_id($subject_id) { global $connection; $query = " SELECT * "; $query .= " FROM subjects "; $query .= " WHERE id=" . $subject_id ." "; $query .= " LIMIT 1"; $result_set = mysqli_query($connection, $query); confirm_query($result_set); if($subject = mysqli_fetch_array($result_set)){ return $subject; }else { return NULL; } } function get_page_by_id($page_id) { global $connection; $query = " SELECT * "; $query .= " FROM pages "; $query .= " WHERE id=" . $page_id ." "; $query .= " LIMIT 1"; $result_set = mysqli_query($connection, $query); confirm_query($result_set); //REMEMBER: // if no rows are returned, fetch_array will return false //** return $page;** on line 58 was bring error instead if($subject = mysqli_fetch_array($result_set)){ }else { return NULL; } } function find_selected_page(){ global $sel_subject; global $sel_page; if (isset($_GET['subj'])) { $sel_subject = get_subject_by_id($_GET['subj']); $sel_page = NULL; } elseif (isset($_GET['page'])) { $sel_subject = NULL; $sel_page = get_page_by_id($_GET['page']); } else { $sel_subject = NULL; $sel_page = NULL; } } ?> Edited March 4, 2015 by laflair13 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.