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

  • Home
  • SEARCH
  • 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 1104027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:25:40+00:00 2026-05-17T01:25:40+00:00

Im creating a simple message board with php/mysql. Users enter their name and a

  • 0

Im creating a simple message board with php/mysql. Users enter their name and a message, javascript displays the message immediately, and php/mysql stores it in a database. When the page loads, it should display all the messages in the database in a formatted list.

However, it seems that my php is displaying only some of the messages arbitrarily. They are in the proper chronological order but some are missing and it only displays 4 of them. Manually looking at the entries in the database, I can see that the posted messages are indeed being stored in their table. They’re just not ALL being displayed. wierd.

Heres the HTML/PHP that displays the messages:

<?php 
    $records = getMessages(); //see getMessages() function below
    $names = $records["names"];
    $messages = $records["messages"];
    $dates = $records["dates"];

    for($i = count($records); $i > 0; $i--){ ?>
    <div class="message">
        <p class="message_txt"><?php echo $messages[$i];?></p>
        <div>
            <div class="message_name">
                <?php echo $names[$i];?>
            </div>
            <div class="message_date">
                <small>
            <?php 
                echo "Posted on ";
                echo date("F j, Y",strtotime($dates[$i]));
        ?>
        </small>
        </div>
    </div>
</div>
<?php } ?>

Heres the getMessages() function from above:

function getMessages(){
    $conn = connect("wedding");
    $ids;
    $names;
    $messages;
    $dates;
    $get_messages_query = "SELECT id, name, message, date 
               FROM messages;";
    $get_messages_result = mysql_query($get_messages_query,$conn) or die(mysql_error());
    $i = 0;
    while($row = mysql_fetch_array($get_messages_result)){
    $ids[$i] = $row["id"];
    $names[$i] = $row["name"];
    $messages[$i] = $row["message"];
    $dates[$i] = $row["date"];
    $i++;
    }

    $entries = array("ids" => $ids,
                     "names" => $names,
                     "messages" => $messages,
                     "dates" => $dates
               ); 
    return $entries;
}

And this is the output:

<div class="message"> 
    <p class="message_txt">Yo this is a message</p> 
    <div> 
    <div class="message_name">Bob</div> 
    <div class="message_date"><small>Posted on September 18, 2010</small></div> 
    </div>                  
</div> 
<div class="message"> 
    <p class="message_txt">This is a message another</p> 
    <div> 
    <div class="message_name">Andrew</div> 
    <div class="message_date"><small>Posted on September 6, 2010</small></div> 
    </div> 
</div> 
<div class="message"> 
    <p class="message_txt">And another message</p> 
    <div> 
    <div class="message_name">Andrew</div> 
    <div class="message_date"><small>Posted on September 6, 2010</small></div> 
    </div> 
</div> 
<div class="message"> 
    <p class="message_txt">This is a message</p> 
    <div> 
    <div class="message_name">Andrew</div> 
    <div class="message_date"><small>Posted on August 27, 2010</small></div> 
    </div> 
</div> 

Im not sure whats going on here. It seems simple enough. I suppose it might be some small idiotic error I can’t see… but I can’t see it.

Any assistance would be appreciated.

  • 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-17T01:25:40+00:00Added an answer on May 17, 2026 at 1:25 am

    The reason is that you’re only looping to 4 explicitly:

     for($i = count($records);
    

    Records is the variable holding the 4 arrays (ids, names, messages, dates). Each array likely holds the correct number of messages, but you’re bounding your loop on records.

    Other Considerations for next time:

    • modify your SQL statement to order these records explicitly. You may see them NOW in the order you expect, but it’s not guaranteed by any RDBMS if you don’t explicitly state the order you wish. Perhaps: SELECT ... FROM... ORDER BY date DESC?

    • The for loop is starting at the bottom. In conjunction with an explicit ORDER BY, consider using

      for($i = 0; i<=count($records);  $i++)
      
    • echo out the count of each array (names, messages, dates). Does that jive with what you expected back from your DB query?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a simple private message system and I'm no sure which database design
I'm creating a threaded message board and I'm trying to keep it simple. There's
I'm creating a simple web application with which a user may author a message
I am creating a simple form based message display system, each message is a
I'm creating quick web app that needs to send a php-created message from within
I'm creating a simple registration page: <?php $firstName = $_POST['firstName']; ?> <form action=registration.php method=post
I'm creating a simple form that takes a referal code and email address, stores
I'm creating a simple application using the Kohana PHP framework, just FYI. This is
I'm creating simple example on JSF. It's small Login application. My problem is duplicate
I am creating simple app on Silverlight 4. In folder of View I have

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.