Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:22:25+00:00 2026-05-28T07:22:25+00:00

I decided to give PHP a try, and then bought lynda.com’s essential training tutorial.

  • 0

I decided to give PHP a try, and then bought lynda.com’s essential training tutorial.
The problem is, that I get this error:

( ! ) Notice: Uninitialized string offset: 0 in
C:\wamp\www\widget_corp\includes\functions.php on line 147.

when trying to compare two values.

Can anyone help me ? 🙂

error in navigation function:

if($page["id"] == $selectedPage['id']){

Class content.php below:

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php");?>
<?php findSelectedPage(); ?>
<?php include("includes/header.php");?>

<table id="structure">
      <tr>
        <td id="navigation">
            <?php echo navigation($selSubject, $selectedPage);?>
            <br/>
            <a href="new_subject.php">+ Add a new subject</a>
        </td>
        <td id="page">
            <?php echo checkSubjOrPage();?>
            <br/>
            <div id="footer">Copyright 2007, Widget Corp</div>
        </td>
      </tr>
   </table>
<?php require("includes/footer.php"); ?>

class function.php below:

<?php
    //This file is the place to store all basic functions.

    //NB!
    //function to prevent problems with submitting values, that contains
    //chars such as: "", '' etc., into the database.
    function mysql_prep($value){
        $magic_quotes_active = get_magic_quotes_gpc;

        //i.e. php>= v4.3.0
        $new_enough_php = function_exists("mysql_real_escape_string");

        if($new_enough_php){
            //undo any magic quotes effects so mysql_real_escape_string can do the work
            if($magic_quotes_active){
                $value = stripslashes($value);
            }
            $value = mysql_real_escape_string($value);
        } else { // before PHP v4.3.0
            //if magic quotes aren't already on then add slashed manually
            if(!$magic_quotes_active){
                $value = addslashes($value);
            }
        }

        return $value;
    }

    function confirm_query($result_set){
        if(!$result_set){
            die("Database connection failed: " . mysql_error());
        }
    }

    function getAllSubjects(){
        global $connection;
        $query = "SELECT *
                    FROM subjects
                    ORDER BY position ASC";

        $subject_set = mysql_query($query, $connection);
        confirm_query($subject_set);

        return $subject_set;
    }

    function getPagesForSubject($subject_id){
        global $connection;
        $query = "SELECT *
                    FROM pages
                    WHERE subject_id = {$subject_id}
                    ORDER BY position ASC";

        $page_set = mysql_query($query, $connection);
        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 = mysql_query($query, $connection);
        confirm_query($result_set);

        //REMEMBER: 
        //if no rows are returned, fetch_array will return false.
        if($subject = mysql_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 = mysql_query($query, $connection);
        confirm_query($result_set);

        //REMEMBER: 
        //if no rows are returned, fetch_array will return false.
        if($page = mysql_fetch_array($result_set)){
            return $page;
        } else {
            return NULL;
        }
    }

    function checkSubjOrPage(){
        global $selSubject;
        global $selectedPage;

        if(!is_null($selSubject)){
            return "<h2>" . $selSubject['menu_name'] . "</h2>";
        } else if(!is_null($selectedPage)){
            return "<h2>" . $selectedPage['menu_name'] . "</h2>" . "<div>" . $selectedPage['content'] . "</div>";
        } else {
            return "<h2>" . "Select a subject or page to edit!" . "</h2>";
        }
    }

    function findSelectedPage(){
        global $selSubject;
        global $selectedPage;

        if(isset($_GET['subj'])){
            $selSubject = get_subject_by_id($_GET['subj']);
            $selectedPage = "";
        } else if(isset($_GET['page'])){
            $selSubject = NULL;
            $selectedPage = get_page_by_id($_GET['page']);
        } else {
            $selectedPage = NULL;
            $selSubject = NULL;
        }
    }

    function navigation($selSubject, $selectedPage){
        $output =  "<ul class=\"subjects\">";
        //3. Perform our database query
        $subject_set = getAllSubjects();

        while($subject = mysql_fetch_array($subject_set)){
            $output .= "<li";
            if($subject["id"] == $selSubject['id']){
                $output .= " class=\"selected\"";
            }  
                $output .= "><a href=\"content.php?subj=" . urlencode($subject["id"]) .
                "\">{$subject["menu_name"]}</a></li>";

                $page_set = getPagesForSubject($subject["id"]);

                $output .= "<ul class=\"pages\">";   
                while($page = mysql_fetch_array($page_set)){
                    $output .= "<li";
                    if($page["id"] == $selectedPage['id']){
                        $output .= " class=\"selected\"";
                }
                    $output .= "><a href=\"content.php?page=" . urlencode($page{"id"}) .
                    "\">{$page["menu_name"]}</a></li>";
                }
                $output .= "</ul>";
            }

                $output .= "</ul>";

                return $output;
    }
    function getPositions(){
        $subject_set = getAllSubjects();
        $subject_counts = mysql_num_rows($subject_set);
        $output = "<select name=\"position\">";

        //$subject_counts + 1 b/c we are adding a subject.
        for($count = 1; $count <= $subject_counts +1; $count++){
            $output .= "<option value=\"{$count}\">{$count}</option>";
        }

        return $output . " </select>";
    }

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:22:25+00:00Added an answer on May 28, 2026 at 7:22 am

    here you override $selectedPage to a string or set it to null

    function findSelectedPage(){
            global $selSubject;
            global $selectedPage;
    
            if(isset($_GET['subj'])){
                $selSubject = get_subject_by_id($_GET['subj']);
                $selectedPage = "";
            } else if(isset($_GET['page'])){
                $selSubject = NULL;
                $selectedPage = get_page_by_id($_GET['page']);
            } else {
                $selectedPage = NULL;
                $selSubject = NULL;
            }
        }
    

    And here it should be an array:

    if($page["id"] == $selectedPage['id']){
    

    function findSelectedPage(){
        global $selSubject;
        global $selectedPage;
    
        if(isset($_GET['subj'])){
            $selSubject = get_subject_by_id($_GET['subj']);
            $selectedPage = NULL;
        } else if(isset($_GET['page'])){
            $selSubject = NULL;
            $selectedPage = get_page_by_id($_GET['page']);
        } else {
            $selectedPage = NULL;
            $selSubject = NULL;
        }
    }
    
    function navigation($selSubject, $selectedPage){
        $output =  "<ul class=\"subjects\">";
        //3. Perform our database query
        $subject_set = getAllSubjects();
    
        while($subject = mysql_fetch_array($subject_set)){
            $output .= "<li";
            if(isset($selSubject['id']) && $subject["id"] == $selSubject['id']){
                $output .= " class=\"selected\"";
            }  
            $output .= "><a href=\"content.php?subj=" . urlencode($subject["id"]) .
            "\">{$subject["menu_name"]}</a></li>";
    
            $page_set = getPagesForSubject($subject["id"]);
    
            $output .= "<ul class=\"pages\">";   
            while($page = mysql_fetch_array($page_set)){
                $output .= "<li";
                if(isset($selectedPage['id']) && $page["id"] == $selectedPage['id']){
                    $output .= " class=\"selected\"";
            }
                $output .= "><a href=\"content.php?page=" . urlencode($page{"id"}) .
                "\">{$page["menu_name"]}</a></li>";
            }
            $output .= "</ul>";
        }
    
        $output .= "</ul>";
    
        return $output;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I decided to give MongoDB a try and see how well we get along.
I'm coming from a TortoiseSVN background and decided to give TortoiseHg a try. One
I have decided to take up f# as my functional language. My problem: Give
On our development team, we decided to give Unit Testing a try. We use
--UPDATE: I've decided to give AFNetworking a try. Even though RestKit has a really
I recently decided to give matplotlib.pyplot a try, while having used gnuplot for scientific
For an iPhone App I decided to give a try to a NoSQL DB,
From the world of PHP I have decided to give C# a go. I've
I decided to give CodeRush/Refactor a go (after a rial of Resharper) and one
I am new to Silverlight and have decided to give it a go. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.