Save items of app menu sample

Hey guys I hope you can help me.

I wonder how the items could save the example of “app menu”. Using php and mysql database.

You can use DataStore and DataProcessor in client side and connector as the servers-side solution. Check 10_server/02_saving/03_list_dataprocessor.html sample - it shows to dataprocessor and connector can be used. In menu app you may use DataStore instead of list as there is no need to render ordered items in a separate list:

var orderList= new dhx.DataStore({ data:[] }) var dp = new dhx.DataProcessor({ master: orderList, url:"data.php", autoupdate: false });

When the menu item is selected, you will either add a new item in DataStore (orderList) or increase its count:

$$("submenu").on_click["buy_outside"] = function(e){ var id = this.locate(e); var data = this.item(id); ... if(!orderList.item(id)) orderList.add({id:id , count: data.Count}) else orderList.item(id).count= data.Count; ... return true };

If “-” button is pressed, you should remove an item or decrease its count:

$$("submenu").on_click["buy_dec_outside"] = function(e){ var id = this.locate(e); var data = this.item(id); data.Count --; ... if (!data.Count){ orderList.remove(id) this.unselect(id); } else{ orderList.item(id).count = data.Count; this.refresh(id); } ... };

To send the ordered items to the server you need to call dp.send() method.

as the file is data.php for mysql.

I could not connect.

10_server/02_saving/03_list_dataprocessor.html uses sqlite db. You need set correct db connection, and omit the second parameter (dbtype) in JSONDataConnector - MySQL is default db.

I’m sending you the source of my application.
I’m having trouble connecting to my database in mysql.
I wonder what could be wrong?

Thank you for your attention.

:bulb:
order.zip (15.7 KB)

There is the following line in data.php
$data = new JSONDataConnector($db,$dbtype);

where $db is defined in config.php:
$db = new GridConnector($res, $dbtype);

Why ?

Here data.php should contain something like:

$data = new JSONDataConnector($res);

where $res is:
$res=mysql_connect(“localhost”,“root”,“sqlmestre”);

|My file data. php is as:

<?php $connector_path = "../connectors/"; require_once($connector_path."data_connector.php"); require_once($connector_path."grid_connector"); $res=mysql_connect("localhost","root","sqlmestre"); mysql_select_db("bioextratus"); $data = new JSONDataConnector($res); $data->render_table("dist_pedido_itens", "id", "count"); ?>

and not used the config.php.

But still could not salve the data to the mysql database.

How do I test the connection?

I have not had many difficulties to compose screens, but to connect the components with the database, I’m having enough trouble.

I’ll do some more tests.

Thanks for the help that is always giving me.

graciously

You can enable logs to get more details about the errors that relate connector usage:

$data = new JSONDataConnector($res);
$data->enable_log(“conn.log”);
$data->render_table(“dist_pedido_itens”, “id”, “count”);

docs.dhtmlx.com/doku.php?id=dhtm … tor:errors

If there is problem with db connection, we can not help.