Can you elaborate a bit on this?
Dolphin/Cheetah stores references to commonly used things in a globally accessible array.
The $GLOBALS['MySQL'] entry is assigned in db.inc.php and is a reference to a instance of the ChWsbDb class.
$GLOBALS['MySQL']->
Can you elaborate a bit on this? Dolphin/Cheetah stores references to commonly used things in a globally accessible array. The $GLOBALS['MySQL'] entry is assigned in db.inc.php and is a reference to a instance of the ChWsbDb class. |
$GLOBALS['MySQL']->
Can you elaborate a bit on this? |
The getAll function i pointed out in my last example would eliminate the need to you to use that loop. Don't mean to hijack the thread but this does bring up a question about the database functions. I will need to convert a module that has php mysql functions coded into the module instead of Cheetah db functions. Are all the functions I need contained in ChWsbDb.php or are there other database function classes as well? Yes. All of them are in ChWsbDb.php. |
The getAll function i pointed out in my last example would eliminate the need to you to use that loop. Don't mean to hijack the thread but this does bring up a question about the database functions. I will need to convert a module that has php mysql functions coded into the module instead of Cheetah db functions. Are all the functions I need contained in ChWsbDb.php or are there other database function classes as well? |
yes, I do realize that there are several functions. since I was using a code sample, I was trying to make sure things worked one step at a time. now that you have helped me pass this hurdle, hopefully I will be able to get everything else I need to figured out. thanks again. |
The getAll function i pointed out in my last example would eliminate the need to you to use that loop. |
originally i was just using a php page inside the module (modules/ccf/apps/top_menu.php) just to make sure that the query and results was working properly. after that was working, then I was trying to add it into the module as my originally question asked. I did get it figured out with:
header("Content-type: application/json; charset=utf-8");
$result = db_res('SELECT * FROM `sys_menu_top` WHERE `Parent` = 0 AND `Visible` LIKE \'%non%\' AND `Type` IN (\'top\', \'custom\') ORDER BY `Parent` ASC'); $dbdata = array();
while ( $row = $result->fetch()) { $dbdata[]=$row; }
echo json_encode($dbdata);
I was trying to use global values but got a bit confused. probably because I need to get some sleep. thanks |
It looks like your writing this as if it was outside of a cheetah module. $query = 'SELECT * FROM `sys_menu_top`'; $rows = $GLOBALS['MySQL']->getAll($query); echo json_encode($rows); } |
ok, so this is what I have and it does work, but I don't want to hard code the database info. I want to use the /inc/header.inc.php page, but can't seem to get it to work. I have tried several different ways to use php to turn mysql queried data into json. I get a blank page with everything else that I have tried.
function actionJson () { header("Content-type: application/json; charset=utf-8"); //require_once('inc/header.inc.php');
$dns = 'mysql:host=localhost;dbname=dbname'; $user = 'username'; $pass = 'dbpassword';
try{ $db = new PDO ($dns, $user, $pass);
} catch( PDOException $e){ $error = $e->getMessage(); echo $error; } $query = 'SELECT * FROM `sys_menu_top`'; $stm = $db->prepare($query); $stm->execute(); $rows = $stm->fetchAll(PDO::FETCH_ASSOC); echo json_encode($rows); } |
In you modules main module class. That's the class ending with module.php in the classes folder.
|
so, I created a new module. I need a page that just returns json data - which is info I am going to pull in from the database.
this is the code:
I want to access this page as you would any other module page using the following url scheme for example: http://cheetahsite.com/m/newmodule/getjson
any help would be greatly appreciated. |