I need to count the number of results for pagination.
Demo Query
select A.order_id,
IF(
E.assign_date IS NOT NULL AND E.assign_date != '0000-00-00',
DATE_FORMAT(E.assign_date , '%d-%b-%y'),
(select data from other tables with other conditions)
) AS assign_date,
.......
where
.....
and assign_date > 2013-08-01
Count Query which I am using
Select count(A.order_id) from order A, size B, production E ........... where ....... and assign_date > 2013-08-01
I need to add that if condition so I can count the results properly
Longer Version
I have checked the questions posted on SO, and couldnt find the answer. I am working on a page where I am showing pagination.
For pagination I have used the count, which is working. Count query is not having this condition.
For actual query I wish I could post my whole query over here but it is over 200+ lines if sorted well.
For pagination I am using the following query.
$strQuery = "SELECT COUNT(DISTINCT(A.order_id)) AS totalRecs FROM $tbls WHERE $whereClause $WhereExt";
The $tbls
and $whereClause
are very long.
In orders
table I m having assing_on
date field, which shows that an order is assigned to some one for production. I have created the result list page from the data, and in PHP added check that if assign_on
date is empty/null. If it is I am running another query to get estimated start date of production.
The estimated start date of production gets a date on number of calculations and parameters
- Orders.estimated delivery date (this is set when posting the order)
- mustReadyDate = estimated date - shipment buffer (another table) - vendor holidays (another 3 tables) - vendor weekends (another 2 tables)
- totalDaysRequired for production = total length of order / Standard weave rate per day (another table)
- muststartdate = mustReadyDate - totalDaysRequired;
Above four points are all in query, no PHP work involve
Data fetch query is having this condition and count query is not having this condition at the moment.
IF(
E.assign_date IS NOT NULL AND E.assign_date != '$mysqlEmptyDate',
DATE_FORMAT(E.assign_date , '" . reporting_DateFormat . "'),
($mustLoomStartDateQry_fm)
) AS assign_date,
I need to add one more condition in where clause of count query to check if aasign_date > one week from today
I just want to know how I can add such a long query in count part so I only execute on query.
** EDIT **
If any one is interested in viewing the full query http://pastebin.com/zqzbpEei but please I am providing you this only to give you the insight...