This topic is locked

extract parameters from query string

7/15/2014 6:13:49 AM
PHPRunner General questions
F
Francesco_5000 author

hi,
I need to extract from the query string of this address

https://myapplication.org/my_report.php?q=(date~equals~2014-2-6~date13)(site~equals~HOUSTON)


some $_get variables to feed an event. Using str_replace , I can change this ~equals~ into this = . And I'm thinking to use str_replace once again to eliminate the unuseful parts like this one ~date13. I'm just wondering if there is a simpler way to accomplish the result, and I ask how phprunner treat the query strings.

F
Francesco_5000 author 7/15/2014

I answer myself, this is what I did:



<?php
$stringa = $_SERVER['QUERY_STRING'];
$originari = array("q=(", "~equals~", "~date13",")(",")");
$sostituiti = array("", "=", "","&","");
$newphrase = "_".str_replace($originari, $sostituiti, $stringa)."_";
preg_match('~_(.*?)&~', $newphrase , $DataOutput);

$dataRilevazione = $DataOutput[1];
preg_match('~&(.*?)_~', $newphrase , $NomeOutput);

$nomeSito= $NomeOutput[1];

?>


are there any better alternative?

Admin 7/15/2014

Rather than telling us what doing trying to explain what you need to achieve. Most likely you won't need to parse the URL after all.

F
Francesco_5000 author 7/15/2014



Rather than telling us what doing trying to explain what you need to achieve. Most likely you won't need to parse the URL after all.


I don't understand the answer because IMHO I wrote what I did, it wasn't my intention to tell to anyone what to do <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=75233&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> . Anyway, the scenario is this:
I've a table with different types of cameras installed in different sites, then I've a report for this table. I need to retrieve the sub-totals of any type of camera for any site. Considering all the conditions, I set a code snippet with a query. The activation of the snippet it's related with a search, this is the reason why I parsed the url. I think there is a better way to achieve the result, I'm just wondering how.

Admin 7/15/2014

To avoid dealing with search parameters extraction and executing the same query more than once simply calculate your totals and subtotals on the fly using events like BeforeProcessList. Example of this approach can be found in this article: http://www.asprunner.com/forums/topic/21091-implementing-running-total-in-phprunner/

F
Francesco_5000 author 7/16/2014



To avoid dealing with search parameters extraction and executing the same query more than once simply calculate your totals and subtotals on the fly using events like BeforeProcessList. Example of this approach can be found in this article: http://www.asprunner.com/forums/topic/21091-implementing-running-total-in-phprunner/


In other situations I used the custom fields but this case is a little different:


If i use a custom field like so (the code is simplified) I've all the cameras of all the sites observed during all the audits.



$sql2="SELECT COUNT(camera.id_camera) AS nr

FROM camera, audit

WHERE audit.id_audit=".$data["fk_audit_camera"]."

GROUP BY audit.id_audit";
$result2 = CustomQuery($sql2);
while ($data2 = db_fetch_array($result2))
$value= "There are [".$data2["nr"]."] cameras; ";


Instead of this, I need something that allows me to follow the "group by" options specified in in the "Group" tab of phprunner.

Admin 7/16/2014

You lost me. I have no idea what kind of functionality you trying to implement.
Just in case check this article that shows how you can access search parameters:

http://xlinesoft.com/phprunner/docs/print_search_parameters_on_list_page.htm