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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:04:47+00:00 2026-06-15T16:04:47+00:00

I want to sort the data from a mysql database when clinking in the

  • 0

I want to sort the data from a mysql database when clinking in the header of a html table. I wrote this code:

$username = $_SESSION['username']; // gets the username

echo "<table class='normal_table'>";

$new_word = mysql_query("SELECT * FROM new_word WHERE username='$username'");
$new_word2 = mysql_query($new_word);

echo " 

<tr>
<th><a href='test.php?sort=cz'>Czech:</a></th>
<th><a href='test.php?sort=en'>English:</a></th>
<tr>";

if ($_GET['sort'] == 'cz')
{
 $new_word .= " ORDER BY cz";
}
elseif ($_GET['sort'] == 'en')
{
 $new_word .= " ORDER BY en";
}

while($new_word2 = mysql_fetch_array($new_word)){

echo "
<tr>
<td> ".$new_word2['cz']."</td>
<td>".$new_word2['en']."</td>
</tr>

"; }

echo "</table>";

But on the screen does not appear any data whatsoever 🙁 What I did wrong?

  • 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-15T16:04:48+00:00Added an answer on June 15, 2026 at 4:04 pm

    You’re executing your query at

    $new_word = mysql_query("SELECT * FROM new_word WHERE username='$username'");
    

    then attempting to appen to that query object at

    $new_word .= " ORDER BY en";
    

    You need to build the query string first

    so

    $sql =  "SELECT * FROM new_word WHERE username='$username'"
    

    append your ORDER BY

    $sql .= " ORDER BY en";
    

    then execute

    $new_word = mysql_query($sql);
    

    EDIT: Also remove $new_word2 = mysql_query($new_word); and change your while to use $new_world as Uttam Kadam says in their answer

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

Sidebar

Related Questions

I want to sort data from mysql. The shema looks like this: id int(11)
I am trying to sort data from on this page: http://www.excelwrestling.com/sortbymostwinsbyweight.php I want the
I want to get data from the database (MySQL) by JPA, I want it
I have data that I want to pull from a mySQL database and I
I have html table that get data from mysql. Every 5 seconds I check
So basically I am running a mysql query that fetches data from my database
If i have data in my MySQL like this table: data(TEXT) foo (hal) foo
I want to update data from my database using java. I have established my
I have a site that displays data on travel products from a MySQL database.
I can't seem to perform the proper selections from mySQL data. $sort = $_GET['sort'];

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.