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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:18:33+00:00 2026-05-31T06:18:33+00:00

I am trying to order data from the table ‘tech_inquiry’ by the Field ‘number’

  • 0

I am trying to order data from the table ‘tech_inquiry’ by the Field ‘number’ in descending order. This should put the results in order by year. Each ‘number’ field corresponds to another field with a title/date (what is actually viewed by visitors) which I can’t sort by because the date is at the end of the title and not always in the same place.

Also, the table ‘tech_inquiry_allowed’ determines what is viewable to who when logged in.

With that said, here is the code:

<?
        $query2=mysql_query("SELECT * FROM tech_inquiry_allowed where term_code = '$term_code' ");
        while($row2=mysql_fetch_assoc($query2))
            {
                $id2=$row2['id'];
                $query3=mysql_query("SELECT * FROM tech_inquiry WHERE id= '$id2' ORDER BY number DESC");
                $row3=mysql_fetch_assoc($query3);
                $name3=$row3['name'];
                    ?> 
                        <hr />
                        <li><a href="get_file.php?id=<? echo $id2; ?> "><? echo $name3; ?> </a> </li> 
                    <?   
            }
    ?>

Also, I have another ‘admin’ section that is able to order data correctly. The only difference is there is no conditional ‘where’ clause because no user authentication is needed (it is used to add data to the table).

Here is that code:

<? 
$query2= mysql_query("SELECT * from tech_inquiry ORDER BY number DESC");
while($row2=mysql_fetch_assoc($query2))
{
    $id2=$row2['id'];
    $name2=$row2['name'];
    ?> 
    <hr />
    <li><a href="get_file.php?id=<? echo $id2; ?> "><? echo $name2; ?> </a> </li> 

    <?

I am wondering if it might be the fact that we are running a query inside a loop.

  • 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-31T06:18:35+00:00Added an answer on May 31, 2026 at 6:18 am

    There are a number of problems here. First of all you only need one query to accomplish this. Please read up on SQL query writing when you get a moment. You will find it to be VERY helpful.

    Second, you are using way more code than you need to. Below is the much simplified, cleaner, and probably faster code.

    <?php
    $query = mysql_query("SELECT * FROM tech_inquiry ti WHERE id IN (SELECT id FROM tech_inquiry_allowed where term_code = '$term_code') ORDER BY ti.number");
    
    while ($row = mysql_fetch_object($query)) {
      echo "<hr />\n<li><a href='get_file.php?id={$row->id}'>{$row->name}</a></li>";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying to insert multiples rows of data from one table to
I am trying to order the data in the table by using the following
I'm writing a plugin and trying to request some data from a custom table
I am currently using phonegap and trying to display results from a sqlite table
I'm trying to get data from the database in order to create a list
I'm trying to pull data from 2 tables and when I add this in
I am trying to select data from a table, using two date fields (startdate
I'm getting error Not unique table/alias while trying to display data from MySQL database
I'm trying to figure out how to select data from a MySQL table based
I'm trying to aggregate some customer order data into one table for analysis. The

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.