$query = $db->query("SELECT `tid`, `tcategory`, `turl`, `tname`, `tfile_text`, `tcount`, `tprice`, `tdone_users`, `trepost`, `tcomments` FROM `tasks` WHERE `tvk_id` != $vk_id AND `tdel` != 1 AND `tsuccess` = 0 AND `tid` NOT IN($tasks_done) ORDER BY `tprice` DESC LIMIT $start_ent, 50"); $num = $db->num($db->query("SELECT `tid` FROM `tasks` WHERE `tvk_id` != $vk_id AND `tdel` != 1 AND `tsuccess` = 0 AND `tid` NOT IN($tasks_done)")); 

How can you make it easier to count everything with 1 query and output 50 records in one? And then some kind of double query is obtained ...

  • one
    And if in the first request just add COUNT ( tid ) AS cnt ? Or by " calculate everything ", did you mean something else? - Deonis
  • @Deonis, because it will show 50, even if there are 150 materials. LIMIT 50 is the same ... - ModaL
  • 2
    Do I like these entries unreadable? or am I just used to indenting ... - teanYCH

1 answer 1

Yes, I did not carefully looked first.

In general, you can do this:

 $query = "SELECT t1.`tid`, t1.`tcategory`, t1.`turl`, t1.`tname`, t1.`tfile_text`, t1.`tcount`, t1.`tprice`, t1.`tdone_users`, t1.`trepost`, t1.`tcomments`, t3.`cnt` FROM `tasks` t1 JOIN (SELECT COUNT(t2.`tid`) AS `cnt` FROM `tasks` t2 WHERE t2.`tvk_id` != $vk_id AND t2.`tdel` != 1 AND t2.`tsuccess` = 0 AND t2.`tid` NOT IN($tasks_done)) t3 WHERE `t1.`tvk_id` != $vk_id AND t1.`tdel` != 1 AND t1.`tsuccess` = 0 AND t1.`tid` NOT IN($tasks_done) ORDER BY t1.`tprice` DESC LIMIT $start_ent, 50"; 

Only in my opinion, not much sense in this.

  • @Deonis, weird. But your SELECT COUNT ( ) AS cnt worked at LIMIT 50 and started to give everything: >> SELECT COUNT ( ) AS cnt FROM tasks WHERE tvk_id ! = $ Vk_id AND tdel ! = 1 AND tsuccess = 0 AND tid NOT IN ($ tasks_done) ORDER BY tprice DESC LIMIT $ start_ent, 50 but the problem is different now. How do I get the data I need? for example tid , tname ? COUNT ( tid ) refused :( - ModaL