Jump to content

I'm having problem with pulling pages content from database


malma

Recommended Posts

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

Link to comment
Share on other sites

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 by laflair13
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.