• [email protected]

    (@fernandoazevedogmailcom)


    Hi,
    I made up a SQL query to get the data I want.
    But it displays the Shortcode and not the chart.

    CAN YOU HELP ME OUT WITH IT?

    // EXAMPLE CHART
    global $wpdb;
    $num_registros = $wpdb->get_results( ‘SELECT item_id FROM wp_frm_item_metas WHERE field_id = 126’ );

    echo ‘<div>[wp_charts title=”barchart” type=”bar” align=”alignleft” margin=”5px 20px” datasets=”‘;
    foreach ( $num_registros as $num_registro)
    {
    echo $num_registro->item_id . ‘,’; ;
    }

    echo ‘”]</div>’;

    The result on my page is [wp_charts title=”barchart” type=”bar” align=”alignleft” margin=”5px 20px” datasets=”98,94,90,89,88,”], But I can’t get the chart to show!

    https://www.ads-software.com/plugins/wp-charts/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Looks like “[email protected]” you are not telling WP to use php. Try using the “Insert PHP” plugin

    I’ve done mine like this and it works for me, (I’ve deleted all the labels and settings to make it clearer). I only dynamically fill the ‘datasets’ and/or labels, not the whole shortcode.

    <div><?php
    echo do_shortcode('[wp_charts title="twitterChart" animation="false" type="line" datasets="' . $data . '" labels="xxx"]');
    ?></div>

    Here try this for your situation, obviously change $data to fill with your MySQL query.

    $data = "98,94,90,89,88";
    
    echo do_shortcode('[wp_charts title="barchart" type="bar" align="alignleft" margin="5px 20px" datasets="' . $data . '"]');

    I haven’t tested this but it works on mine, if there’s any errors just echo out your $data to ensure your foreach loop is building $data correctly.

    If that doesn’t work, look at possibly changing your foreach loop for a for loop? I personally build my query with the below because my columns are numbered from 1 > 100:

    $sql = "SELECT * FROM temperatur WHERE area = ‘london’ LIMIT 1″;
    $result = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($result);

    for ($x=1; $x<=100; $x++) {
    $data .= $row[‘$x’] . “,”;
    };

    echo $data;`

    Hope this sets you on the right path! The dev of this app seems to have died so thought I’d try help.

    Ryan

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Passing the number via php’ is closed to new replies.