NogDog;11027455 wrote:Maybe...
'/FROM.*(?=GROUP BY|ORDER BY|LIMIT|$)/sU'
However, if this is something to do with your question about pagination, I'd me more inclined to explicitly defining it myself. To that end, you can sort of avoid repeating yourself by defining that part first, then incorporating it into each query:
$sqlCore = "FROM
emp_contacts
LEFT JOIN emp_contacts_cache ON emp_contacts.mobile_no = emp_contacts_cache.mobile_no
WHERE emp_contacts.mobile_no = emp_contacts_cache.mobile_no
";
$sqlMain = "SELECT
emp_contacts.mobile_no,
emp_contacts.fname,
emp_contacts_cache.data_source,
emp_contacts_cache.name_summary
$sqlCore
ORDER BY emp_contacts.name ASC LIMIT 0,100";
$sqlTotal = "SELECT COUNT(*)
$sqlCore";
ey man, thanks. and like laserlight said it is related to the other topic.. i hope this is not considered duplicate topic..i wanted to organize my questions...
anywho... thanks for the samples.. but i' actually simplifying my code, make it cleaner and easier to read.. your code sample is perfectly fine.. but as you can see you had to do 2 different sql statements, and that means having to debug /modify 2 statements if need be.. and the added lines to do the logic in loops during constructing it etc.. now multiply that to the many other sql queries you have to build and it's a headache to read/debug..
my approach is much more simple .. not too many hoops and loops during
just create the query you need, STRAIGHT FORWARD , and just worry about the conditions you need to code for the query itself..
put all that in a simple $q variable
pass it to the function
eg. query_select($q, $rowlimit,$curpage);
, and let the function parse the select statement to create the needed count statement .. and add the LIMIT clause to the original $q statement as needed 🙂
hence i need this Regex to extract just the conditions i need ..
To be honest, i was thinking of simply splitting the sql at FROM keyword, and just add SELECT count(*) to the rest of the query .. hmm.. perhaps that's a more simple approach huh?
$q_parts = explode("$q","FROM");
$q_count = "SELECT count(*) " . $q_parts[1];
etc...
hmmmmm