Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
ordering by 2 columns
Old 01-10-2012, 12:35 PM ordering by 2 columns
Average Talker

Posts: 22
Trades: 0
I have a table with 2 columns I need to sort. The first column is "id" and the second is "job". As jobs are entered into the database they are giving an "id" but if 2 people are working on the same job then the "job" field is given the same number as the "id" field. For example:

id job
1
2
3
4 2
5

So I would like the order to show up as rows with the following id: 1, 2, 4, 3, 5
so that the job show as such: 1, 2, 2, 4, 5

The ordering does not come out correct. Here is the php
PHP Code:
<?php
//create order by
$query="SELECT * FROM lss WHERE month=$month AND day=$day";
$result mysql_query($query) or die("Couldn't execute query: ".mysql_error());
while (
$rows=mysql_fetch_array($result)) {
$id=$rows['id'];
$jobdb=$rows['job'];
if (
$jobdb=="") {
$job="id";
} else {
$job="job";
}
}
//list
$query="SELECT * FROM lss WHERE month=$month AND day=$day ORDER BY $job";
$result mysql_query($query) or die("Couldn't execute query: ".mysql_error());
?>

Last edited by beylah; 01-10-2012 at 12:42 PM..
beylah is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-10-2012, 12:46 PM Re: ordering by 2 columns
Average Talker

Posts: 22
Trades: 0
i have found my error

I need to wrap the while {} around both queries
beylah is offline
Reply With Quote
View Public Profile
 
Old 01-11-2012, 07:03 AM Re: ordering by 2 columns
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
For future reference, ORDER BY clause, eg

select id, job-id from my-table order by id, job-id
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-12-2012, 02:22 PM Re: ordering by 2 columns
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by PaulW View Post
For future reference, ORDER BY clause, eg

select id, job-id from my-table order by id, job-id
Keep in mind from Paul's comment that the ORDER BY goes in order of columns listed from left to right. So the two examples below would result in two different results.

ORDER BY id, type

ORDER BY type, id
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ordering by 2 columns
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13344 seconds with 12 queries