Advertisement

01.26.2007 at 01:32PM PST, ID: 22138610
[x]
Attachment Details

MySQL Query Sort

Asked by kerkor in PHP and Databases

Tags: mysql, query, sort, tree

Here is the table structure:

cdata_id
users_id
field_id
value

I am interested in only some of the fields value's for the users.

Here is what I am using now:
$query = "SELECT lm_users.users_id, lm_cdata.cfield_id, lm_cdata.value FROM lm_users
INNER JOIN lm_cdata ON lm_users.users_id = lm_cdata.user_id WHERE lm_users.group_id =2
AND (
lm_cdata.cfield_id = '1'
OR lm_cdata.cfield_id = '2'
OR lm_cdata.cfield_id = '3'
OR lm_cdata.cfield_id = '11'
OR lm_cdata.cfield_id = '12'
OR lm_cdata.cfield_id = '9'
) order by lm_users.users_id";

But this means I have to do all of my own sorting for tree like structure in programming. Is there any way to sort this using SQL?

This is how I wish to use the data from this query:
Country 1 (cfield_id= 2) [Start with United States, then followed alpha by other countries]

State 1 (cfield_id= 1)
  City (cfield_id= 3)
    Participant 1 (cfield_id= 9)
      event description (cfield_id= 12)
    Participant 2 (cfield_id= 9)
      event description (cfield_id= 12)
  City 2 (cfield_id= 3)
    Participant 3 (cfield_id= 9)
     event description (cfield_id=12)
  Participant 4 (cfield_id= 9)
State 2 (cfield_id= 1)

I have been struggling for several days on this. Any help or advice would be so much appreciated.

Seeking sanity,
KerKorStart Free Trial
[+][-]01.26.2007 at 01:53PM PST, ID: 18407786

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.26.2007 at 11:01PM PST, ID: 18409252

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.27.2007 at 05:47AM PST, ID: 18409991

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: mysql, query, sort, tree
Sign Up Now!
Solution Provided By: kerkor
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.31.2007 at 07:51AM PST, ID: 18436713

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32