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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:55:32+00:00 2026-05-25T13:55:32+00:00

I have put together a basic order list for admin users in php for

  • 0

I have put together a basic order list for admin users in php for checking order contents placed by logged in users.

The aim of this script is to retrieve the order details (item, quantity, price) as well as the user’s first name and surname (where ‘Order for:’ is).

The script below does everything ok in that it retrieves the order (and orders if there are more than one) and it’s/their item, quantity and price.

However, it doesn’t display the user’s name and surname.

I know the problem is that where I am trying to display the name is outside the while loop but Im a little stuck in where it should sit. Any suggestions? Code is below:

    <?php 
    $page_title = 'View Individual Order';
    include ('includes/header.html');

    // Check for a valid user ID, through GET or POST.
   if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) )
    { // Accessed through view_users.php   
     $id = $_GET['id'];

    } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) )
   { // Form has been submitted.   
    $id = $_POST['id'];
} else { // No valid ID, kill the script.
    echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
    include ('./includes/header.html'); 
    exit();
}
?>

<h1>Order Details</h1>

<?php
require_once ('database.php'); // Connect to the db.

// Retrieve the user's, order and product information.
$query = "SELECT us.users_id, us.users_sales_id, us.users_first_name, us.users_surname, us.users_dealer_name, 
             ord.order_id, ord.users_id, ord.total, ord.order_date,  
             oc.oc_id, oc.order_id, oc.products_id, oc.quantity, oc.price,
             prd.products_id, prd.products_name, prd.price      
         FROM users AS us, orders AS ord, order_contents AS oc, products AS prd  
         WHERE ord.order_id=$id
         AND us.users_id = ord.users_id
         AND ord.order_id = oc.order_id
         AND oc.products_id = prd.products_id    
         ";

$result = mysql_query ($query) or die(mysql_error());

if (mysql_num_rows($result)) { // Valid user ID, show the form.

    echo    '<p>Order for:<strong>' . $row[2] . ' ' . $row[3] . ' </strong> </p>
            <table border="0" style="font-size:11px;" cellspacing="1" cellpadding="5">
                <tr class="top">
                <td align="left"><b>Product</b></td>
                <td align="center"><b>Price</b></td>
                <td align="center"><b>Qty</b></td>
                </tr>';

    $bg = '#dddddd'; // Set the background color.

    while($row = mysql_fetch_array($result, MYSQL_NUM)) { // WHILE loop start

    $bg = ($bg=='#eaeced' ? '#dddddd' : '#eaeced');

    echo        '<tr bgcolor="' . $bg . '">';

    echo        '<td align="left">' . $row[15] . '</td>
            <td align="center">' . $row[13] . ' pts</td>
            <td align="center">' . $row[12] . '</td>
            </tr>';

    echo        '';         

                }// end of WHILE loop

        echo '</table>
            <p> Here:</p>   
            <br><br>
            <p><a href="view-all-orders.php"> << Back to Orders</a></p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            ';

} else { // Not a valid user ID.
    echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">This page has been accessed in error.</p><p><br /><br /></p>';   
}

mysql_close(); // Close the database connection.
?>

<p>Footer here</p>

<?php
include ('./includes/footer_admin_user.html'); // Include the HTML footer.
?>
  • 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-25T13:55:32+00:00Added an answer on May 25, 2026 at 1:55 pm

    One way you could do it is grab the row first, and then use a do/while loop instead of just a basic while loop. Like this:

    if (mysql_num_rows($result)) { // Valid user ID, show the form.
    
        /*********** I added this line ***********/
        $row = mysql_fetch_array($result, MYSQL_NUM);
    
        echo    '<p>Order for:<strong>' . $row[2] . ' ' . $row[3] . ' </strong> </p>
                <table border="0" style="font-size:11px;" cellspacing="1" cellpadding="5">
                    <tr class="top">
                    <td align="left"><b>Product</b></td>
                    <td align="center"><b>Price</b></td>
                    <td align="center"><b>Qty</b></td>
                    </tr>';
    
        $bg = '#dddddd'; // Set the background color.
    
        /*********** I changed this from a while loop to a do-while loop ***********/
        do { // WHILE loop start
    
        $bg = ($bg=='#eaeced' ? '#dddddd' : '#eaeced');
    
        echo        '<tr bgcolor="' . $bg . '">';
    
        echo        '<td align="left">' . $row[15] . '</td>
                <td align="center">' . $row[13] . ' pts</td>
                <td align="center">' . $row[12] . '</td>
                </tr>';
    
        echo        '';         
    
        } while($row = mysql_fetch_array($result, MYSQL_NUM)); // end of WHILE loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok, so I put together a very basic mail function and while testing this,
I have put together this code for creating a dynamic form unit Unit1; interface
I'm trying to minimize my code and have put together this little snippet, it
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
I have put together a script which is very much like the flickr photostream
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
I am a powershell novice. After days of searching.... I have put together a
Hello I have problem to put together animations of two separate objects to second
I have a utility that I put together that uses the .NET Framework to
I have MANY small Test Projects where I put together just enough code to

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.