sort mysql results after query... need expert advice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

sort mysql results after query... need expert advice

Post by scarface222 »

removed
Last edited by scarface222 on Fri Feb 12, 2010 4:40 pm, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: sort mysql results after query... need expert advice

Post by social_experiment »

What information will be displayed with the second query? If there is an id of the user inside the first query, you could possibly use that to tie the two queries together?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: sort mysql results after query... need expert advice

Post by scarface222 »

Thanks for the response man

well each table does have an id called topic_id for each topic.

information would look like this in while statement

Code: Select all

 
$topic_id=$row['topic_id'];
$creator=$row['creator'];
$description=$row['description'];
$topic_title=$row['topic_title'];
I thought about tying them like that, I just was not sure how to since the full first query must be executed to get the number of users. The second query just says topic title, usernumber (from first query function), who created the topic etc. I just wanted to sort the results by usernumber determined by first query but wasn't sure how since they queries are of two separate tables.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: sort mysql results after query... need expert advice

Post by social_experiment »

Since you are selecting everything from the table, you could use a mysql_fetch_array() to get the value $value['topic_id']. Once you have that, you could do a join between the two tables, but if the second table has all the information you need displayed, then a join with the first table wont be neccessary. If however you do need something from the first table a join might look something like this :

Code: Select all

<?php $sql = "SELECT * FROM to JOIN scrusersonline ON to.topic_id = scrusersonline.topic_id ORDER BY scrusersonline.usernumber ASC"; ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: sort mysql results after query... need expert advice

Post by scarface222 »

removed, I am a dumbass lmao. I do not want to say what the problem was. I was just extremely careless.
Post Reply