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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:52:13+00:00 2026-06-07T00:52:13+00:00

I have a user database which I want the admin to be able view

  • 0

I have a user database which I want the admin to be able view users. I want the admin to be able to sort the users by different fields. (E.g first name or surname).

My problem:
Is that it wont sort. Im trying to do it using a drop down box and a submit button. I have have tried the Sql in phpMyAdmin to make sure the statement is correct which it is. I have also added a or die to make sure its not a mysql error. Im getting no errors its just not sorting. I have also tried echoing out the drop down to make sure the right value is being added to the variable.

code:
HTML drop down

  <form action="View_users.php" enctype="multipart/form-data" name="sort" id="sort" method="post" align="right">
        <label>
          <select name="sortdropdown" id="sortdropdown">
          <option value="<?php echo $sortby; ?>"><?php echo $sortby; ?></option>
          <option value="name">First Name</option>
          <option value="surname">Surname</option>
          <option value="email">Email</option>
          <option value="signupdate">Date</option>
          </select>
        </label>
        <label>
             <input type="submit" name="button" id="button" value="Sort" />
        </label>
     </form>

logic:

$sortby = "";
if (!isset($_POST['sortdropdown'])) {
            $sortby = "surnname";
    }else{
    $sortby = mysql_real_escape_string($_POST['sortdropdown']);
    }
// This block grabs the whole list for viewing
$product_list = "";
$counter = 0;
$sql = mysql_query("SELECT * FROM users ORDER BY '$sortby' ASC")  or            die(mysql_error());

$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){ 
            $counter++;
             $id = $row["id"];
            $email = $row["email"];
            $name = $row["name"];
            $surname = $row["surname"];
            $lastlogin = $row["lastlogin"];
            $signupdate = $row["signupdate"];
            if (is_float($counter/2)) {$class = "#CCCCCC"; }
            else {$class = "white";}
            $product_list .= '<tr bgcolor="'.$class.'">
            <td>'.$surname.'</td>
            <td>'.$name.'</td>
            <td>'.$email .'</td>
            <td><a href="user.php?id=' . $id . '">View More</a></td></tr>';
     }
 } else {
$product_list = "There are no users in the system yet";
}

Thanks

  • 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-07T00:52:14+00:00Added an answer on June 7, 2026 at 12:52 am

    The comments are correct, you should be using back ticks `$sortby` instead of ‘$sortby’

    The reason is – single quotes are used to wrap values in MySQL, which is not what you want. You’re passing the name of a table column, so you use back ticks because they are used to wrap table column names.

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

Sidebar

Related Questions

I have a database table for users which contains common fields like password, email
I have an attribute in my user database of type Date. I want to
i have database table with few text fields which i use to filter data
I have a Django app. When logged in as an admin user, I want
The first user in my DB is the Super Admin, and I don't want
I have a members.php page/file in which i want logged in users to see
I have a table in MySQL database from which I want to select a
i have a large user Database (13k+), and for some reason i need to
I have two tables in my database: user and media_contact . The media_contact table
I have a user Sql Authentication account that has remote access to my database

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.