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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:56:43+00:00 2026-05-26T23:56:43+00:00

I would like to ask some help. This is not homework but it is

  • 0

I would like to ask some help. This is not homework but it is just an example on how I want to achieve so I provide example.

Here’s my sample code.

$records = $stmt->prepare("SELECT fname, lname, birthday FROM names ORDER BY birthday DESC");

$records->execute()

foreach($records as $row) {
    $birthday = $row['birthday'];
    $fname = $row['fname'];
    $lname = $row['lname'];

<table>

<tr>
<td>
<?php echo $row['birthday'] . " | " . $row['fname'] . " | " . $row['lname']; ?>
</td>
</tr>
</table>

What I want to achieve is to have a student # before birthday in reverse order.

Student 4 | 1981-11-01 | John | Smith
Student 3 | 1980-11-01 | John | Smith
Student 2 | 1979-11-01 | John | Smith
Student 1 | 1978-11-01 | John | Smith

How can I do that? I have only loop through records and display it but I don’t know how to add Student # in reverse order (old student below and new on top base on birthday)

Thanks a lot.

  • 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-26T23:56:43+00:00Added an answer on May 26, 2026 at 11:56 pm

    You should count the number of rows, print and decrement by one

    $records->execute();
    $num_rows = $records->num_rows;
    
    foreach($records as $row) {
        $birthday = $row['birthday'];
        $fname = $row['fname'];
        $lname = $row['lname'];
    
    <table>
    
    <tr>
    <td>
    <?php echo $num_rows. "|" . $row['birthday'] . " | " . $row['fname'] . " | " . $row['lname']; 
    $num_rows--;
    ?>
    
    </td>
    </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning! I would like to ask some help from you guys on how
I'm still fairly new to mysql and would like to ask for some help.
I would like to ask you about some advices about this code. It works,
I would like to ask some logic question here. Let say I have a
I'm almost sure this is not possible, but just wanted to ask if I'm
I would like to ask for help on how to fix this. I would
I would like to make my application ask the user some informations via something
What I would like ask is best illustrated by an example, so bear with
Hello I would like to ask your help regarding javascript code, how do I
I would like to ask how HAProxy can help in routing requests depending on

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.