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

The Archive Base Latest Questions

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

i have some reference to record for a given article. a reference might be

  • 0

i have some reference to record for a given article. a reference might be of type an article, book, thesis etc..
each might have different attributes, e.g.

//article_refs table
ID Article_ID Article_Title Author_Name ...
1  1          title1        author1
2  1          title2        author2

//thesis_refs table
ID Article_ID Thesis_Title Thesis_Publisher ...
1  1          thesis1      publisher1
2  1          thesis2      publisher2

//ref_types table
ID Article_ID ReferenceType
1  1          book
2  1          article
3  1          article
4  1          book

when i insert into one of the tables, i first into ref_type table with its type (book, article). then insert whichever table it belongs. (e.g. if it is an article, insert into article table)..

now, i have to be able list references in order.

$sql=mysql_query("SELECT * FROM ref_types 
WHERE $article_ID=Article_ID ORDER BY ID ASC");
while($row = mysql_fetch_array($sql)){
    $counter=1;

    if($row[2]=="thesis"){
        $sqlthesis=mysql_query("SELECT * FROM thesis_refs
        WHERE $article_ID=Article_ID 
        ORDER BY ID ASC");
        while($thesis_row = mysql_fetch_array($sqlthesis)){
            echo "record $counter: ";
            echo $row[2];
            echo ", ";
            echo $thesis_row[2];
            echo "<BR>";
            $counter++
        }   
    }elseif.....

this way it lists all thesis records then lists article table etc..

record 1: book1
record 2: book2
record 3: article1
record 4: article2

i know it is simply because of while loop, but how to get this (same order with ref_types table..)??

record 1: book1
record 2: article1
record 3: article2
record 4: book2

any help is appreciated.
thanks in advance..

  • 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-31T01:06:35+00:00Added an answer on May 31, 2026 at 1:06 am

    In addition to having ReferenceType column in ref_types table, you also need a Reference_ID column that refers to the actual ID in the corresponding table as a foreign key.

    //ref_types table
    ID Article_ID ReferenceType Reference_ID
    1  1          book          1
    2  1          article       1
    3  1          article       2
    4  1          book          2
    

    Then, you can avoid a WHILE loop and let MySQL do the work for you with JOINs:

    SELECT CONCAT('record ', rt.ID, ': ',
      COALESCE(ar.Article_Title, tr.Thesis_Title, br.Book_Title))
    FROM ref_types rt
    LEFT JOIN article_refs ar
      ON rt.ReferenceType = 'article' AND ar.ID = rt.Reference_ID
    LEFT JOIN book_refs br
      ON rt.ReferenceType = 'book' AND br.ID = rt.Reference_ID
    LEFT JOIN thesis_refs tr 
      ON rt.ReferenceType = 'thesis' AND tr.ID = rt.Reference_ID
    

    Yields the result:

    record 1: book1
    record 2: article1
    record 3: article2
    record 4: book2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the basic idea is that you have some class that has a reference type
I have some pages that reference javascript files. The application exists locally in a
I am a newbie on optimization. I have been reading some reference on how
I have some types which are generated by a web service reference. I want
Say I have some 10 categories that I need to reference in a web
I have a series of Python classes in a file. Some classes reference others.
Is there a way to have a function return a editable reference to some
can some on help me on how i can reference images i have all
On the class level, I have created reference: System::Data::Odbc::OdbcConnection Connection; in some method I
I have a table that must reference another record, but of the same table.

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.