• Resolved milesnewey

    (@milesnewey)


    Hi All,

    So, over night I have gone from being a complete and utter php amateur, to a semi novice php wizzard – well not really! What I wanted to do was have a plugin that queries a table, brings the results back and puts it in a shortcode to enable me to display it on a page. I was fairly pleased with myself, I got it to work sort of, however the site will not let me in to the wpadmin now as it’s coming up with the following error: Cannot modify header information – headers already sent by (output started at /home/u4641/public_html/jmvasdata.com/wp-content/plugins/sqltblscrape.php:1) . The problem of geting into the admin side is fine as i can just disable the plugin, but I would like to know why the plugin is causing this error, and also, when I use the shortcode it displays the results above the page – can anyone enlighten me please as to how to get the shortcode to display the data in the main page? I would also like to know how to bring this data back into a table, but one thing at a time please! By the way, here is my plugin code, (minus the gumpf about the name of the plugin and the copyright stuff!)

    [code moderated - please follow the forum guidelines for posting code]

Viewing 6 replies - 1 through 6 (of 6 total)
  • http://codex.wordpress.org/FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem.3F

    the output at the top is caused by using echo in the shortcode code; you need to use return

    Thread Starter milesnewey

    (@milesnewey)

    Awesome, thanks alchymyth, it works a treat. Any ideas on how to get it back into a table? Here is my code now, (less than 10 lines – i’m learning all the time!)

    function CountyInstancesOver30($gallery=1) {
    global $wpdb;
    $sql = "SELECT County, COUNT(County) AS Incident FROM tblSpeedData WHERE Speed > 30";
    $result = $wpdb->get_results($sql);
    foreach ($result as $pic)
    {
    return "County: " . $pic->County . ", Incidents: " . $pic->Incident . "<br />";
    }
    }
    add_shortcode('CInstO30', 'CountyInstancesOver30');

    Any ideas on how to get it back into a table?

    I don’t like tables 😉

    not sure what table structure you ahd before, hoewever, you could try to integrate the table code into the shortcode:

    example:
    http://pastebin.com/3TjGaPPt

    Thread Starter milesnewey

    (@milesnewey)

    That’s awesome Alchymyth, works a treat apart from the fact it only brings one row and it should be bringing three…but i am guessing that could be my table/data, unless you can spot anything wrong with the loop? Can I be cheeky and ask how you would display tabular data? Or is it that just generally in this tables are nasty?

    Can I be cheeky and ask how you would display tabular data?

    I would work with divs or spans; although I do admit that tables have advantages in some situations.

    – my dislike comes from the fact that I inherited a vintage website to look after which is entirely based on tables 🙁

    Thread Starter milesnewey

    (@milesnewey)

    hmm interesting to see another approach to it, many thanks again for your help Alchymyth.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Plug in Shotcode not Displaying in correct place’ is closed to new replies.