Jump to content

Multiple tables with multiple order by


selenin

Recommended Posts

Hi

I have a question, my script so far

 

  $site2 = mysql_query("SELECT * FROM `sites` WHERE (`banned` = '0' AND `user`!='{$data->login}') AND  sites.user IN (select concat_ws(',', login) from users WHERE `coins`>=`cpc`) AND `id` NOT IN (SELECT `site_id` FROM `plused` WHERE `user_id`='{$data->id}') ORDER BY `cpc` DESC LIMIT 0, 10");
  $ext = mysql_num_rows($site2);

 

Now it's ordered by cpc desc, but I want to order as well by from the table users coins desc. Then the user with more coins is before the other. But sites.cpc is another table then users.coins, is this possible?

Link to comment
https://forums.phpfreaks.com/topic/251654-multiple-tables-with-multiple-order-by/
Share on other sites

Don't know where to edit my post

 

like that?

 

  $site2 = mysql_query("SELECT * FROM `sites` WHERE (`banned` = '0' AND `user`!='{$data->login}') AND  sites.user IN (select concat_ws(',', login) from users WHERE `coins`>=`cpc`) AND `id` NOT IN (SELECT `site_id` FROM `plused` WHERE `user_id`='{$data->id}') ORDER BY `cpc` DESC LIMIT 0, 10");

You can order by as many expressions as you'd like.

 

$site2 = mysql_query("SELECT * FROM `sites` WHERE (`banned` = '0' AND `user`!='{$data->login}') AND  sites.user IN (select concat_ws(',', login) from users WHERE `coins`>=`cpc`) AND `id` NOT IN (SELECT `site_id` FROM `plused` WHERE `user_id`='{$data->id}') ORDER BY `cpc` DESC LIMIT 0, 10");

 

Yes I know but I want as well order by coins, but coins is from another table, the table users. First it should be ordered by cpc desc and sometimes the cpc are the same the it should be ordered by users.coins

SELECT * FROM `sites` JOIN users 
          ON sites.user = users.login WHERE (`banned` = '0' AND `user`!='{$data->login}') AND  sites.user IN (select concat_ws(',', login) from users WHERE `coins`>=`cpc`) AND `id` NOT IN (SELECT `site_id` FROM `plused` WHERE `user_id`='{$data->id}') ORDER BY `cpc` DESC LIMIT 0, 10

 

I tried it like that but I'm only getting error messages, I really don't understand this JOIN

Yes the error message is simple, because I'm not getting any results, normally I get 10

 

Error message

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/selenin/public_html/artmeo/google.php on line 5

Then show us the output of mysql_error().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.