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.
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
<cfscript>
groups = [];
loop collection="#scheduler_group#" item="group" {
g = {
id: "group_#group.id#",
name: group.name,
expanded: true,
children: []
};
```
<cfquery name="q_res" datasource="db">
SELECT id, name
FROM resources
WHERE group_id = <cfqueryparam value="#g.id#" sqltype="varchar">
ORDER BY name
</cfquery>
```
loop query="q_res" {
arrayAppend(g.children,
QueryRowData(q_res, q_res.currentrow)
);
}
arrayAppend(groups, g);
}
setting showdebugoutput="false";
content reset="Yes" type="application/json";
echo(serializeJson(groups);
abort;
</cfscript>
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(
"
SELECT
*
FROM groups
ORDER BY name
"
);
qResources = queryExecute(
"
SELECT
id,
name
FROM resources
WHERE group_id = :id
ORDER BY name
",
{
'id': {
value = g.id,
cfsqltype = 'varchar'
}
}
);