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 9094741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:25:28+00:00 2026-06-16T23:25:28+00:00

Using PHP 5.3.10, I created a link-list class and am trying to save a

  • 0

Using PHP 5.3.10, I created a link-list class and am trying to save a list of football players.

After calling the add function, it seems that the object never retains any information. var_dump($playerList) returns NULL for both my head and tail pointers. Or, if I replace it with var_dump($playerList->count), it prints nothing no matter where I place the var_dump count statement.

I have been through the manual and cannot find the error in my syntax. My gut is telling me mysql_fetch_array is doing something funky. As stated below, my testing shows that values are in fact being passed around when I call playerList->add(). Anyhow, here is my simple code:

/* Populates lists with available players. */
function populateList($sql)
{
    $playerList = new PlayerList();
    while ($row = mysql_fetch_array($sql, MYSQL_NUM)) 
    {
        $playerList->add(new Player($row[0], $row[1], $row[2], $row[3], $row[4]));
    }
    var_dump($playerList);
}

And my linked list class:

include 'PlayerNode.php';

class PlayerList
{
    public $head;
    public $tail;
    public $count;

    function PlayerList()
    {
        $head = null;
        $tail = null;
        $count = 0;
    }

    function add($player)
    {
        $count ++;            
        $node = new PlayerNode($player);

        //First time in
        if ($head == null)
        {
            $head = $node;
            $tail = $node;
            $head->nextPtr = null;
        }
        // All other times
        else
        {
            $tail->nextPtr = $node;
            $tail = $node;
            $node->nextPtr = null;
        }
        $count++;
    }               
}

I can place var_dump($node) and echo statements in the linked list class and observe that PlayerNode is working correctly.

But, another strange observation… if($head==null) ALWAYS evaluates to true too. Could this be related?

  • 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-06-16T23:25:29+00:00Added an answer on June 16, 2026 at 11:25 pm

    Insertion in the head of the Singly Linked Lists :
    We can easily insert the elements in the head of the list. So how we do it? Create a new node, set the next of the new node point to the current head node, and set the head variable (in the class) point to the new node. This method works even if the Linked List is empty. Note that we set the next of the new node point to the head node, before we sent the head variable to point to the new node.

    Insertion in the tail of the Singly Linked Lists:
    We can also easily insert elements in the tail of the Linked List, provided we keep a reference for the tail node of the Linked Lists. Create an new node set the next of the new node to null, set the next of the tail node point to the new node, set the tail variable to point to the new element. Note we set the next of the previous tail node before we change the tail variable to point to the new node.

    In all the other times add the new node to the head or tail.

                  // All other times if head
                    else{
                            $temp = $head;
                            $head = $node;
                            $node->nextPtr = $temp;
                            count ++; 
                        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load a xml document I created using PHP and DOM
I have created a dynamic list picker script using Jquery 1.3 and PHP that
i have created a forum using php/mysql and users login through facebook using php
I am creating an image dynamically using php. The image is being created if
I used Firebug to inspect the HTML my php(using wordpress) files created. According to
Using Tinybutstrong and openTBS i created a script in PHP that opens multiple docx
I have created a RESTful PHP web service using Lithium which contains comments, each
I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
I am using my admin panel login script where i have created a global.php
I am trying to create a web page using php. The problem is that

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.