Ajax - Database functions [DB Loader problems within Ajax Data page]

Permalink
I am attempting to change some content when a select box is changed.

But am struggling to figure out how to grab information from the db.

This is my current code.
$('#course_select').change(function (event) {
            $.post("/tools/course_tools.php", { selected:$('#course_select').val(),courseID:<?php print $kID?> },
                function (data) {
                    $('#course_details').html(data);
                }
            );
        });


Then in the course_tools.php

$selected = isset($_POST['selected']) ? $_POST['selected'] : 0;
    $courseID = isset($_POST['courseID']) ? $_POST['courseID'] : 0;
    displayCourseInformation($courseID,$selected);
function displayCourseInformation($courseID=0,$selected){
    $db = Loader::db();
    $query = "SELECT query\n";
}


If I don't use the DB loader I can output content. Currently I get
Fatal error: Class 'Loader' not found in. I realise this is because the page is not loading in the static class.

Can anyone point me towards the correct way to pull this information in? can I use concrete tools or do I need to revert to a mysql() command?

Thanks
Sean

TheRealSean
 
Remo replied on at Permalink Best Answer Reply
Remo
That's because you're directly calling the tools php. You have to make sure you open every page through index.php

You can use the following code to get the correct url:

$th = Loader::helper('concrete/urls');
echo $th->getToolsURL('your_tool', 'your_package');
TheRealSean replied on at Permalink Reply
TheRealSean
Thanks for your help Remo,

would this work without the package declaration? I am calling this from a single page. So assume it will be just
$courseAjaxUrl = $th->getToolsURL('your_tool');
$.post("<?php echo $courseAjaxUrl?>", { selected:$('#course_select').val(),courseID:<?php print $kID?> },
                function (data) {
                    $('#course_details').html(data);
                }
            );


[edit]Aha got it, I did not realise until looking at the source that my initial echo for the $courseAjaxURL was not being wrapped with quotations. I had attempted using recommended before but could not get it quite right.

Thanks again
Remo replied on at Permalink Reply
Remo
Great ;-)