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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:49:54+00:00 2026-06-03T02:49:54+00:00

I have this table named categories with three fields as below cat | order

  • 0

I have this table named “categories” with three fields as below

cat     | order | id
--------|-------|----
News    |  3    | 23
Hi-Tech |  2    | 15
Biz     |  5    | 8
Health  |  1    | 3

Also, I have another table named “links” like below

link    | order | cat-id
--------|-------|-------
link1   |  2    | 23
link2   |  8    | 15
link3   |  5    | 8
link4   |  6    | 15
link5   |  2    | 15
link6   |  4    | 23
link7   |  1    | 3
link8   |  1    | 8

What I want to achieve is to sort categories and below each category to sort the links of that category cat-id / id like this below:

Health
link7

Hi-Tech

link5

link4

link2

News

link1

link6



Biz

link8

link3

I succeeded on showing the categories sorted but I am loosing it after it.

My aim is to show this on a page so I guess I have to use PHP and mySQL.

  • 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-03T02:49:56+00:00Added an answer on June 3, 2026 at 2:49 am

    The query is simply this:

    SELECT c.cat, l.link, c.id
    FROM links l INNER JOIN categories c
    ON l.cat-id = c.id
    ORDER BY c.`order`, l.`order`
    

    And here it is at work.

    In order to show it on a page, it would look like this:

    mysql_connect(<host>, <username>, <password>);
    
    $q = mysql_query("<query from above>");
    $last_cat = 0;
    while($row = mysql_fetch_assoc($q)) {
        if($row['id'] != $last_cat) {
            print '<h3>' . $row['cat'] . '</h3>';
            $last_cat = $row['id'];
        }
        print $row['link'] . '<br>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables like this: Person table: person_id | name | dob --------------------------------
I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
I have a table named as categories....with columns... category_id categoryname I want to represent
I have this table : Name | money_earned _______________________ john | 100 paul |
I have this table. id name parents 1 Apparel 46 Apparel 1 47 Child
I have this table layout: uuid bigint(20) unsigned primary auto_increment timestamp int(11) unsigned name
I have a table, table 1. In this table is name, city, price. The
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have this data in a table, for instance, id name parent parent_id 1
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives

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.