• Resolved nicolais12

    (@nicolais12)


    Hi!

    Thank you for sharing all your knowledge contactashish13. I am facing some difficulties…

    I am trying to run the following query through the admin panel:

    SELECT station.name,
    sum(CASE WHEN project_solution_state_date_2.state_id=1 THEN 1 END) AS state1,
    sum(CASE WHEN project_solution_state_date_2.state_id=2 then 1 END) AS state2,
    sum(CASE WHEN project_solution_state_date_2.state_id=3 THEN 1 END) AS state3,
    sum(CASE WHEN project_solution_state_date_2.state_id=4 THEN 1 END) AS state4
    FROM project_solution_state_date_2,station
    WHERE project_solution_state_date_2.project_id = {DINAMIC VALUE} AND station.station_id = project_solution_state_date_2.station_id
    GROUP BY project_solution_state_date_2.station_id

    However, I am not able to set the {DINAMIC VALUE}… I tried to use the snippet that you have facilitated in a previous post, but it does not work. This is what I am trying:

    add_filter( ‘visualizer_db_query’, function( $query, $chart_id ) {
    $query = str_replace( “LIMIT 1000”, “WHERE project_solution_state_date_2.project_id = ” . $DinamicValue . ” LIMIT 1000″, $query );
    return $query;
    }, 10, 2 );

    The variable $DinamicValue gets the value like this:

    $DinamicValue = $_GET[‘course_id’];

    Could you please tell me the way to proceed?

    Thank you very much.

    Best regards,

    Nico

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor contactashish13

    (@rozroz)

    I don’t see from where the filter will get the value of course_id to set it as the $DinamicValue. You need to make sure that whatever you use inside the filter has already been defined/created elsewhere.

    Thread Starter nicolais12

    (@nicolais12)

    $DinamicValue gets the value from $_GET[‘course_id’]; By using an alert, I can see that the $DinamicValue gets always the proper value.

    $DinamicValue is setted before calling the filter.

    I am still using this filter, but it does not work…

    add_filter( ‘visualizer_db_query’, function( $query, $chart_id ) {
    $query = str_replace( "LIMIT 1000", "WHERE project_solution_state_date_2.project_id = " . $DinamicValue . " LIMIT 1000", $query );
    return $query;
    }, 10, 2 );

    I am trying to test it with a hardcoded value (9999), but it still does not recognize it.

    add_filter( ‘visualizer_db_query’, function( $query, $chart_id ) {
    $query = str_replace( "LIMIT 1000", "WHERE project_solution_state_date_2.project_id = 9999 LIMIT 1000", $query );
    return $query;
    }, 10, 2 );

    Shouldnt there be a comma in the second string LIMIT 1000″? Like this:

    `add_filter( ‘visualizer_db_query’, function( $query, $chart_id ) {
    $query = str_replace( “LIMIT 1000”, “WHERE project_solution_state_date_2.project_id = 9999″ ,”LIMIT 1000”, $query );
    return $query;
    }, 10, 2 );`

    Looking forward to your answer

    Plugin Contributor contactashish13

    (@rozroz)

    Can you please add an error_log before and after changing the $query parameter to see what values you get?

    Plugin Contributor contactashish13

    (@rozroz)

    We haven’t heard from you in sometime so marking this as Resolved. If you continue to face an issue, please create a new ticket. We’d be happy to help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dinamic values within a query’ is closed to new replies.