I have used following code for getting category and corresponding course detail in MOODLE
global $DB;
$catlist = $DB->get_records_sql(
'SELECT ca.id,ca.name,ca.coursecount, c.id as course_id , c.category,
c.fullname, c.shortname , c.summary , c.format, c.startdate , c.timecreated
FROM {course_categories} as ca inner join {course} as c on ca.id = c.category
WHERE ca.parent > ? and ca.visible = ? and c.visible = ? ', array('0','1','1'));
echo "<pre>";print_r($catlist); echo "</pre>";
When i execute this query I am getting a result array with only one of the result rows, whereas executing the same sql in the mysql database directly returns many rows.
Table course_categories have 2 category 'account' and 'business' have active condition using visible =1 and also contain parent category. Table course have 4 course 2 of each related to category 'account' and 'business'
result like this:
Array
(
[1] => stdClass Object
(
[id] => 1
[name] => Accounts
[coursecount] => 2
[course_id] => 4
[category] => 1
[fullname] => Finance
[shortname] => Finance
[summary] =>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
[format] => weeks
[startdate] => 1461695400
[timecreated] => 1461653620
)
[2] => stdClass Object
(
[id] => 2
[name] => Business
[coursecount] => 2
[course_id] => 5
[category] => 2
[fullname] => Animal Health Honours (BSc(Hons))
[shortname] => Animal Health Honours
[summary] =>
Sl/NO, Course Name, Duration. HARDWARE & NETWORKING. 1, Advacnce Diploma in Computer Hardware Maintanance & Networking(ADCHMN), 12 Months.
[format] => weeks
[startdate] => 1461781800
[timecreated] => 1461760598
)
)
Can any one help to resolved this problem.