jQuery UI Widgets › Forums › Editors › Input, Password Input, TextArea, ColorPicker, Rating, TagCloud, Loader › jqxInput to MySQL Demo
This topic contains 3 replies, has 2 voices, and was last updated by ivailo 9 years, 3 months ago.
-
AuthorjqxInput to MySQL Demo Posts
-
Hello,
Is there any demo of jqxInput to MySQL ?
I want to create master-detail , master using form input, detail using grid.
Please advise, thank youHi vincmeister,
Here is a demo, adapted to northwind database.
index.html//
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.classic.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxinput.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#jqxinput").jqxInput( { theme: 'classic', width: 200, height: 25, source: function (query, response) { var dataAdapter = new $.jqx.dataAdapter ( { datatype: "json", datafields: [ { name: 'CompanyName', type: 'string'} ], url: 'data.php' }, { autoBind: true, formatData: function (data) { data.query = query; return data; }, loadComplete: function (data) { if (data.length > 0) { response($.map(data, function (item) { return item.CompanyName; })); } } } ); } }); }); </script> </head> <body class='default'> <input id="jqxinput"/> </body> </html>
data.php//
<?php $hostname = "localhost"; $database = "northwind"; $username = "root"; $password = ""; // Connect to the database $mysqli = new mysqli($hostname, $username, $password, $database); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // get data and store in a json array $from = 0; $to = 10; $searchQuery = "{$_GET['query']}%"; // $searchQuery = $_GET['query']; $query = "SELECT CompanyName, ContactName, ContactTitle, Address, City FROM customers WHERE CompanyName LIKE ? LIMIT ?,?"; $result = $mysqli->prepare($query); $result->bind_param('sii', $searchQuery, $from, $to); $result->execute(); /* bind result variables */ $result->bind_result($CompanyName, $ContactName, $ContactTitle, $Address, $City); /* fetch values */ while ($result->fetch()) { $customers[] = array( 'CompanyName' => $CompanyName, 'ContactName' => $ContactName, 'ContactTitle' => $ContactTitle, 'Address' => $Address, 'City' => $City ); } //echo json_encode(utf8_encode($customers)); $json = html_entity_decode(json_encode($customers)); echo $json; /* close statement */ $result->close(); /* close connection */ $mysqli->close(); ?>
Best Regards,
Ivailo IvanovjQWidgets Team
http://www.jqwidgets.comHello Ivailo,
Thank you for the respond. I meant for the sql insert into (add new row) to mysql
Please advise, thank youHi vincmeister,
Here is a demo how to send post request to the server script.
Then you can manipulate and insert your data to MySQL.Best Regards,
Ivailo IvanovjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.