Convert PHP into CFML - Help!

Hi everyone

I’m trying to write a planner app as part of a very large project.
The planner I have found is daypilot (Javascript) and has a few php files which populate/add/edit etc. the planner/calendar.

I need some help re-writing the php into cfm code as I’ve NEVER used php.

Could anyone help me?

There are 8 php files all less than 30 lines.

Thanks in advance!

1 Like

Can you post some of the PHP snippets you don’t know how to convert into CFML?

Here you go Zac, nothing too complicated I’m sure.

require_once '_db.php';
$scheduler_groups = $db->query('SELECT * FROM groups ORDER BY name');

class Group {}
class Resource {}

$groups = array();

foreach($scheduler_groups as $group) {
  $g = new Group();
  $g->id = "group_".$group['id'];
  $g->name = $group['name'];
  $g->expanded = true;
  $g->children = array();
  $groups[] = $g;
  $stmt = $db->prepare('SELECT * FROM resources WHERE group_id = :group ORDER BY name');
  $stmt->bindParam(':group', $group['id']);
  $scheduler_resources = $stmt->fetchAll();  
  foreach($scheduler_resources as $resource) {
    $r = new Resource();
    $r->id = $resource['id'];
    $r->name = $resource['name'];
    $g->children[] = $r;

header('Content-Type: application/json');
echo json_encode($groups);

I’m using a Lucee specific tag island ``` to swtich from script to tags and back, because I prefer the readability of the older cfquery tag syntax to the more modern QueryExecute()

You could also use a return type of struct for cfquery, but I wanted to demonstrate QueryRowData

	groups = [];
	loop collection="#scheduler_group#" item="group" {
		g = {
		    id: "",
		    expanded: true,
		    children: []

		<cfquery name="q_res" datasource="db">
			SELECT 	id, name 
			FROM 	resources 
			WHERE  	group_id = <cfqueryparam value="" sqltype="varchar">
			ORDER 	BY name
		loop query="q_res" {
			    QueryRowData(q_res, q_res.currentrow)
		arrayAppend(groups, g);
	setting showdebugoutput="false";
	content reset="Yes" type="application/json";
1 Like

Thanks so much Zac, but I can’t see the equivalent of the line:

$scheduler_groups = $db->query('SELECT * FROM groups ORDER BY name');

Or am I missing something?

I didn’t realise you could use ``` to go in and out of cfscript

Hey @GaryH,

As @Zackster said, I would use queryExecute. I think the formatting is prettier and matches better with what you are use to. Here are your two queries:

qGroups = queryExecute(
    FROM groups 
    ORDER BY name

qResources = queryExecute(
    FROM resources 
    WHERE group_id = :id
    ORDER BY name
        'id': {
            value =, 
            cfsqltype = 'varchar'

That’s great - thanks guys.

I’ll give that a go today!