iam using JQuery jTable and PHP for my Website.
While Loading Data from Database work perfectly! but when Update the Data: send POST to
edit the rows doesent update MySQL database, just jtable, but after reload the Page "load from mysql" the data is back to befor update.
Delete data work, only update don`t update
my js:
//Prepare jTable
$('#log').jtable({
title: 'Domains',
toolbar: {
hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
hoverAnimationDuration: 60, //Duration of the hover animation.
hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
items: [] //Array of your custom toolbar items.
},
paging: true,
sorting: true,
pageSize : 10,
pageSizes : [ 2, 5, 10, 15, 20, 50, 75, 100, 200, 500 ],
defaultSorting: 'domain ASC',
actions: {
listAction: 'actions.php?action=list',
createAction: 'actions.php?action=create',
updateAction: 'actions.php?action=update',
// deleteAction: 'actions.php?action=delete'
},
messages: DeutschMessages,
fields: {
id_domain: {
key: true,
title: 'ID',
create: false,
edit: false,
list: true
},
domain: {
title: 'Domainname',
width: '30%'
},
exclude: {
title: 'Exclude',
defaultValue: 'www,ns,ftp,mail,mx,pop,smtp',
width: '40%'
},
dnsip: {
title: 'DNS Server',
width: '20%'
},
key: {
title: 'Key',
sorting: false,
list: false,
width: '20%'
},
enable_a: {
title: 'A',
options: ['1','0'],
sorting: false,
width: '20%'
},
enable_ns: {
title: 'NS',
options: ['1','0'],
sorting: false,
width: '20%'
},
enable_url: {
title: 'URL',
options: ['1','0'],
sorting: false,
width: '20%'
},
max: {
title: 'MAX',
defaultValue: '-1',
sorting: false,
width: '20%'
}
}
});
//Load person list from server
$('#log').jtable('load');
});
and the php script:
//Open database connection
$con = mysql_connect($mysql_host,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db,$con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
if (empty($_POST['search']))
{
$search = NULL;
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM domains;");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
$result = mysql_query("SELECT * FROM domains ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
}
else
{
$search = mysql_real_escape_string($_POST['search']);
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%';");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%' ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
$_SESSION["query"] = "SELECT * FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%' ORDER BY " . $_GET["jtSorting"];
$_SESSION["contador"] = "SELECT COUNT(*) AS RecordCount FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%'";
}
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $rows;
$jTableResult['TotalRecordCount'] = $recordCount;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO `domains`(`id_domain`, `domain`, `exclude`, `dnsip`, `key`, `enable_a`, `enable_ns`, `enable_url`, `max`) VALUES ('', '".$_POST["domain"]."','".$_POST["exclude"]."','".$_POST["dnsip"]."','".$_POST["key"]."','".$_POST["enable_a"]."','".$_POST["enable_ns"]."','".$_POST["enable_url"]."','".$_POST["max"]."');");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM domains WHERE id_domain = last_insert_id();"); // WHERE id_domain = last_insert_id();"); // id_domain = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
$id = $_REQUEST['id_domain'];
//Update record in database
$result = mysql_query("UPDATE domains SET domain = '" . addslashes($_POST["domain"]) . "', exclude = '" . addslashes($_POST["exclude"]) . "', dnsip = '" . addslashes($_POST["dnsip"]) . "', key = '" . addslashes($_POST["key"]) . "', enable_a = '" . addslashes($_POST["enable_a"]) . "', enable_ns = '" . addslashes($_POST["enable_ns"]) . "', enable_url = '" . addslashes($_POST["enable_url"]) . "', max = '" . addslashes($_POST["max"]) . "' WHERE id_domain = $id;");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
else if($_GET["action"] == "listname")
...
after hit Update:
Response is always "ok"
i can´t catch the error ./
any help ?
Have you seen this?
updateAction: 'actions.php?action=update',
// deleteAction: 'actions.php?action=delete'
should be:
updateAction: 'actions.php?action=update'
// deleteAction: 'actions.php?action=delete'
without the comma at the end of the first line (you removed the following row so this is the last one.
Furthermore: you should consider to switch to PDO for mysql safe site.
Last but not least: you are not handling errors in the insert query. Try something like:
if(mysql_query("INSERT INTO `domains`
(`id_domain`, `domain`, `exclude`, `dnsip`, `key`, `enable_a`, `enable_ns`, `enable_url`, `max`)
VALUES
('','".$_POST["domain"]."','".$_POST["exclude"]."','".$_POST["dnsip"]."','".$_POST["key"]."','".$_POST["enable_a"]."','".$_POST["enable_ns"]."','".$_POST["enable_url"]."','".$_POST["max"]."');")){ $jTableResult['Result'] = "OK";
}else{
$jTableResult['Result'] = "KO";
}
Related
I have created an autosuggestion search box using PHP and jQuery. The user is prompted to insert First name and Last name to find someone that exists in my database, in a table called customers. Table customers holds 2 columns, first_name and last_name.
My search works fine when you type the First name but after pressing space to move and type Last Name does not give any results. The whole problem seems to appear when pressing space button. Any idea how to fix it?
$(document).ready(function($){
$("#customers").autocomplete({
source: "fetch_customers.php?cc=<?php echo $agencyid; ?>",
minLength: 2,
select: function(event, ui) {
var code = ui.item.id;
if (code != '#') {
location.href = '/view-customer/' + code;
}
},
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
});
<?php
$countrycode1 = $_GET['cc'];
$term = trim(strip_tags($_GET['term']));
$term = preg_replace('/\s+/', ' ', $term);
$a_json = array();
$a_json_row = array();
$a_json_invalid = array(array("id" => "#", "value" => $term, "label" => "Only letters and digits are permitted..."));
$json_invalid = json_encode($a_json_invalid);
if ($data = $conn->query("SELECT id, first_name, last_name FROM customers WHERE agency_id='$countrycode1' AND (first_name LIKE '%$term%' OR last_name LIKE '%$term%') ORDER BY first_name , last_name"))
{
while($row = mysqli_fetch_array($data))
{
$firstname = htmlentities(stripslashes($row['first_name']));
$lastname = htmlentities(stripslashes($row['last_name']));
$code = htmlentities(stripslashes($row['id']));
$a_json_row["id"] = $code;
$a_json_row["value"] = $firstname.' '.$lastname;
$a_json_row["label"] = $firstname.' '.$lastname;
array_push($a_json, $a_json_row);
}
}
/* jQuery wants JSON data */
$json = json_encode($a_json);
print $json;
flush();
$conn->close();
Split Your $term like this.
$splited_term = explode(" ",$term);
$first_term = $splited_term[0];
$last_term = (isset($splited_term[1]) && !empty($splited_term)) ? $splited_term[1] : null;
Generate your query according
$query = "SELECT id, first_name, last_name FROM customers WHERE agency_id='$countrycode1' AND ";
if(!empty($first_term)){
$query.= "(first_name LIKE '%$first_term%' OR last_name LIKE '%$first_term%'" ;
}
if(!empty($last_term)){
$query .= ((!empty($first_term)) ? " OR " : " ( " )." first_name LIKE '%$last_term%' OR last_name LIKE '%$last_term%')" ;
}
$query .= ((empty($last_term)) ? ")" : "")." ORDER BY first_name , last_name";
This will support
"Milind Patel"
"Patel Milind"
" Milind"
" Patel"
"Milind"
"Patel"
So Your code should be like this.
<?php
$countrycode1 = $_GET['cc'];
$term = trim(strip_tags($_GET['term']));
$term = preg_replace('/\s+/', ' ', $term);
$splited_term = explode(" ",$term);
$first_term = $splited_term[0];
$last_term = (isset($splited_term[1]) && !empty($splited_term)) ? $splited_term[1] : null;
$a_json = array();
$a_json_row = array();
$a_json_invalid = array(array("id" => "#", "value" => $term, "label" => "Only letters and digits are permitted..."));
$json_invalid = json_encode($a_json_invalid);
$query = "SELECT id, first_name, last_name FROM customers WHERE agency_id='$countrycode1' AND ";
if(!empty($first_term)){
$query.= "(first_name LIKE '%$first_term%' OR last_name LIKE '%$first_term%'" ;
}
if(!empty($last_term)){
$query .= ((!empty($first_term)) ? " OR " : " ( " )." first_name LIKE '%$last_term%' OR last_name LIKE '%$last_term%')" ;
}
$query .= ((empty($last_term)) ? ")" : "")." ORDER BY first_name , last_name";
if ($data = $conn->query($query))
{
while($row = mysqli_fetch_array($data))
{
$firstname = htmlentities(stripslashes($row['first_name']));
$lastname = htmlentities(stripslashes($row['last_name']));
$code = htmlentities(stripslashes($row['id']));
$a_json_row["id"] = $code;
$a_json_row["value"] = $firstname.' '.$lastname;
$a_json_row["label"] = $firstname.' '.$lastname;
array_push($a_json, $a_json_row);
}
}
/* jQuery wants JSON data */
$json = json_encode($a_json);
print $json;
flush();
$conn->close();
Someone who knows about JTable? I´ve tried to create a specfici table with this plugin however I can´t find the right way. I donwloaded the examples and modify it for my needs. But after change the code I have a blank page only in the browser.
Can someone explain to me where is/are the mistake/s?
index.php
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Table of people',
paging: true,
pageSize: 50,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: 'PersonActionsPagedSorted.php?action=list',
createAction: 'PersonActionsPagedSorted.php?action=create',
updateAction: 'PersonActionsPagedSorted.php?action=update',
deleteAction: 'PersonActionsPagedSorted.php?action=delete'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false,
width: '5%',
},
Fecha: {
title: 'Fecha',
width: '10%',
type: 'date',
}
Nombre: {
title: 'Nombre',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3','4': 'Option4' }
},
Turno: {
title: 'Turno',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
Info: {
title: 'Info',
width: '45%',
type: 'textarea'
},
Estado: {
title: 'Estado',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
Criticidad: {
title: 'Criticidad',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
}
});
//Load person list from server
$('#PeopleTableContainer').jtable('load');
});
</script>
PersonActionsPagedSorted.php
<?php
try
{
//Open database connection
$con = mysql_connect("localhost","root","");
mysql_select_db("jtabletestdb", $con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get record count
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM people;");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM people ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO people(Fecha, Nombre, Turno, Info, Estado, Criticidad) VALUES('" . $_POST["Fecha"] . "', '" . $_POST["Nombre"] . "','" . $_POST["Turno"] . "', '" . $_POST["Info"] . "','" . $_POST["Estado"] . "', '" . $_POST["Criticidad"] . ";");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
//Update record in database
$result = mysql_query("UPDATE people SET Fecha = '" . $_POST["Fecha"] . "', Nombre = '" . $_POST["Nombre"] . "', Turno = '" . $_POST["Turno"] . "', Info = '" . $_POST["Info"] . "',Estado ='" . $_POST["Estado"] . "', Criticidad = '" . $_POST["Criticidad"]. "' WHERE PersonId = " . $_POST["PersonId"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Deleting a record (deleteAction)
else if($_GET["action"] == "delete")
{
//Delete from database
$result = mysql_query("DELETE FROM people WHERE PersonId = " . $_POST["PersonId"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Close database connection
mysql_close($con);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
?>
If you wonder, yeah I´m very novice in this world and I suppose the answer is simple.
I have two tables one for user and one for search. When I drag a search over to user it adds entire search list. How do I only insert the item dragged and not the entire search array?
THE PROBLEM IS recordsArray.
<?php
require("db.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
if ($action == "updateRecordsListings"){
$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
$query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, update query failed');
//INSERTS array item that does NOT EXIT in userTable
if (mysql_affected_rows()==0) {
$query = mysql_query("INSERT INTO records1 SELECT * FROM records WHERE recordID = " . $recordIDValue);
$query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, insert/update query failed');
}
$listingCounter = $listingCounter + 1;
}
echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>
Both list arrays id must maintain the same id names in order for the above item to acknowledge and process the list items. Keeping things simple I just used the same code for the Search, User format:
<li id="recordsArray_<?php echo $result['recordID']; ?>"><?php echo $result['recordID'] . ". " . $result['recordText']; ?></li>
Javascript:
$(function() {
$("#contentLeft ul, #main ul").sortable({ accept: '.draggable', connectWith: "#contentLeft ul", opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("updateDB.php", order, function(theResponse){
$("#contentRight").html(theResponse);
});
}
});
}).disableSelection();
});
How can I call only the recordsArray items from #content ul?
I can only get one insert per refresh with this but it does drag and drop insert...
Still need an if statement for possible errors because +/-1 if
<?php
require("db.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
$uRA = $updateRecordsArray;
// Get total number of elements in $updateRecordsArray
$ifArray = $updateRecordsArray;
$resultCount = count($ifArray);
//echo '<br />';
//print_r($resultCount);
// Get total number of rows in $records1
$recordTable = array();
$result = mysql_query("SELECT recordListingID FROM records1");
$numRows = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
$recordTable = array_merge($recordTable, array_map('trim', explode(",", $row['recordListingID'])));
}
//Gets $id/$val of elements not in both arrays
$results = array_diff($uRA, $recordTable);
//echo '<br />';
//print_r($numRows);
//Give variables for +/- 1 $numRows
$plusNumRows = $numRows + 1;
$minusNumRows = $numRows - 1;
//echo '<br />';
//print_r($minusNumRows);
// Normal jQuery drag and drop ranking found online
if ($action == "updateRecordsListings"){
$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
//If statement for for +/- 1 $numRows
If ($resultCount == $numRows -1 || $resultCount == $numRows || $resultCount == $numRows + 1){
$sql = mysql_query("INSERT INTO records1 SELECT * FROM records WHERE recordID = $recordIDValue");
}
$query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, update query failed');
$listingCounter = $listingCounter + 1;
}
echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>
I’m working on a PHP application integrated to shopify. Basically product information must be sync between the "shop" and application. Inside the products we have variants (similar to sub products). Shopify used to send webhooks with json data to report these changes. Every time I change/add/delete a variant, shopify send a "product update" webhook that changes only the json content. This is a example:
{
...
"variants": [{
"id": 279656846,
"position": 1,
"price": "80.00",
"product_id": 123022448,
"sku": "1000",
"option1": "30 cm",
"inventory_quantity": 10
},
{
"id": 291321287,
"position": 2,
"price": "15.00",
"product_id": 123022448,
"sku": "1003",
"option1": "15 cm",
"inventory_quantity": 23
}],
...
}
If I create a new variant it sends me a "product update" with current status, and has the new variant in json. Similarly, if I delete, it only send me a "product update" with current status, but without the deleted variant in json.
I created the following code that can treat properly the change/add case:
foreach ($jsonArr['variants'] as $rows) {
$variant = $rows['option1'];
$sku = $rows['sku'];
$salesPrice = $rows['price'];
$stockQty = $rows['inventory_quantity'];
$idVar = $rows['id'];
$dupchk = mysql_query("SELECT * FROM `variants` WHERE `idVar`='$idVar'",$con) or die (mysql_error());
$num_rows = mysql_num_rows($dupchk);
if ($num_rows > 0) {
$sql = "UPDATE `variants` SET `variant`='$variant',`sku`='$sku',`salesPrice`='$salesPrice',`stockQty`='$stockQty' WHERE `idVar`='$idVar'";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
else {
$sql = "INSERT INTO `variants`(`idVariant`, `idProduct`, `variant`, `sku`, `salesPrice`, `stockQty`, `comments`, `idVar`) VALUES ('','$idProduct','$variant','$sku','$salesPrice','$stockQty','','$idVar')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
}
The problem is that this code does not handle the delete variant case. I tried to do it but until now only create a "big confusing" code that could not work. Please, advise if you have any suggestion to a smart way to handle it.
To solve I used following code:
//Variable to count variant update or create
$var_count = 0;
foreach ($jsonArr['variants'] as $rows) {
$variant = $rows['option1'];
$sku = $rows['sku'];
$salesPrice = $rows['price'];
$stockQty = $rows['inventory_quantity'];
$idVar = $rows['id'];
$dupchk = mysql_query("SELECT * FROM `variants` WHERE `idVar`='$idVar'",$con) or die (mysql_error());
$num_rows = mysql_num_rows($dupchk);
if ($num_rows > 0) {
$sql = "UPDATE `variants` SET `variant`='$variant',`sku`='$sku',`salesPrice`='$salesPrice',`stockQty`='$stockQty' WHERE `idVar`='$idVar'";
$var_count++;
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
else {
$sql = "INSERT INTO `variants`(`idVariant`, `idProduct`, `variant`, `sku`, `salesPrice`, `stockQty`, `comments`, `idVar`) VALUES ('','$idProduct','$variant','$sku','$salesPrice','$stockQty','','$idVar')";
$var_count++;
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
}
//Start checking to erase variant if needed
$result = mysql_query("SELECT `idVar` FROM products NATURAL JOIN variants WHERE `idShopify`='$idShopify'",$con);
$num_rows = mysql_num_rows($result);
if ($num_rows>$var_count) {
while($row = mysql_fetch_array($result))
{
$clear = 0;
foreach ($jsonArr['variants'] as $rows) {
if ($rows['id']==$row['idVar']) {
$clear++;
}
}
if ($clear==0) {
$idVar = $row['idVar'];
$sql = "DELETE FROM `variants` WHERE `idVar`='$idVar'";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
}
}
This is not elegant but worked. Feel free to suggest code improvements.
I have a static code to update some select boxes.
The original structure code:
$result = "
({
'options': [
{'value': '','description': '(pick an item)'},
{'value': 'test','description': 'test'},
{'value': 'test_2','description': 'test_2'}
]
});
";
I'm trying to make this dynamic and connect to my table in Postgresql Database but my code don't works.
Here is My Code:
if($value=="asus"){
require("includes/connection.php");
$sth = $dbh->prepare( "SELECT * FROM mapa_ferias WHERE area = 'Asus' " );
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$result = "
({
'options': [";
while($row = $sth->fetch()) {
$result += "{'value': '" + $row['nome'] + "','description': '" + $row['nome'] + "'},";
}
$result +=
"]
});
";
}
I hope you can help me. Thanks in advance.
Please do not try to build JSON data yourself.. PHP has a function for it: json_encode()
if ($value=="asus"){
require("includes/connection.php");
$sth = $dbh->prepare( "SELECT * FROM mapa_ferias WHERE area = 'Asus' " );
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$options = array();
while($row = $sth->fetch()) {
$options[] = array(
'value' => $row['nome'],
'description' => $row['nome']
);
}
$sth->closeCursor();
$result = '('.json_encode(array(
'options' => $options
)).')';
}