Hello guys i am new to both ajax and JSON and i have followed this guide on making a jquery slider and getting some result from DB it is working but right now i can only get one result from the slider range but i want to get all results from that range so i need to pass more then one result variable from my php and cant seem to get it to work i have included my code below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script src="slider.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div>
<span id="deal_min_price"></span>
<span id="deal_max_price" style="float: right"></span>
<br /><br />
<div id="slider_price"></div>
<br />
<span id="number_results"></span> Abonnementer fundet
</div>
</body>
</html>
$(document).ready(function()
{
$( "#slider_price" ).slider({
range: true,
min: 0,
max: 349,
step:1,
values: [ 0, 349 ],
slide: function( event, ui ) {
$( "#deal_min_price" ).text(ui.values[0] + "KR");
$( "#deal_max_price" ).text(ui.values[1] + "KR");
},
stop: function( event, ui ) {
var dealsTotal = getDeals(ui.values[0], ui.values[1]);
$("#number_results").text(dealsTotal);
},
});
$("#deal_min_price").text( $("#slider_price").slider("values", 0) + "KR");
$("#deal_max_price").text( $("#slider_price").slider("values", 1) + "KR");
});
function getDeals(min_price, max_price)
{
var numberOfDeals = 0;
$.ajax(
{
type: "POST",
url: 'deals.php',
dataType: 'json',
data: {'minprice': min_price, 'maxprice':max_price},
async: false,
success: function(data)
{
numberOfDeals = data;
}
});
return numberOfDeals;
}
PHP:
<?php
$result = 0;
define('MYSQL_HOST', 'db564596075.db.1and1.com');
define('MYSQL_USER', 'dbo564596075');
define('MYSQL_PASSWORD', '12345678');
define('MYSQL_DB', 'db564596075');
try
{
$dbh = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DB, MYSQL_USER, MYSQL_PASSWORD);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_PERSISTENT, true);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
catch (PDOException $e)
{
echo 'Fejk: ' . $e->getMessage() . '<br/>';
}
if(isset($_POST['minprice']) && isset($_POST['maxprice']))
{
$minprice = filter_var($_POST['minprice'] , FILTER_VALIDATE_INT);
$maxprice = filter_var($_POST['maxprice'] , FILTER_VALIDATE_INT);
$query = '
SELECT
*
FROM
mobilabonnement
WHERE
Prisprmdr
BETWEEN
:minprice
AND
:maxprice
';
$stmt = $dbh->prepare($query);
try
{
$stmt->bindParam(':minprice', $minprice);
$stmt->bindParam(':maxprice', $maxprice);
$stmt->execute();
}
catch (PDOException $e)
{
print($e->getMessage());
die;
}
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$result = $row['Selskab'];
}
if ($result == true)
{
echo json_encode($result);
}
else{
echo json_encode(0);
}
?>
Here is why You got only Selskab - $result = $row['Selskab'];
Try that:
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$result = $row;
if ($result)
{
echo json_encode($result);
}
else
{
echo json_encode(0);
}
You need to loop over all the results or use PDO::fetchAll, if you want all the columns you also need to use the whole row not just Selskab:
$result = array();
while (false !== ($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
$result[] = $row;
}
if (count($result)
{
echo json_encode($result);
} else{
echo json_encode(0);
}
OR using PDO::fetchAll:
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($result)
{
echo json_encode($result);
} else{
echo json_encode(0);
}
However it also seems you really only want Selskab and id as opposed to all of the columns and in that case you should probably adjust your query as well:
SELECT id, Selskab
FROM mobilabonnement
WHERE Prisprmdr BETWEEN :minprice AND :maxprice
Related
I have PHP program to pull data from a MS SQL Server and encode the result in JSON
Here is the code below ->
<?php
/*
connect to MS SQL Server using PHP
*/
$serverName = "192.168.0.4,14333"; // ip:port
$connectionInfo = array( "Database"=>"YYY", "UID"=>"XX", "PWD"=>'XX');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br /><pre>";
die( print_r( sqlsrv_errors(), true));
}
$tsql = "
SELECT * FROM projections_sample
";
$getResults= sqlsrv_query($conn, $tsql);
echo ("Reading data from table" . PHP_EOL);
if ($getResults == FALSE)
die(FormatErrors(sqlsrv_errors()));
$rows1 = array();
$rows1['name'] = 'Revenue';
while ($r1 = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC))
{
$rows1['data'][] = $r1['revenue'];
}
$getResults= sqlsrv_query($conn, $tsql);
echo ("Reading data from table" . PHP_EOL);
if ($getResults == FALSE)
die(FormatErrors(sqlsrv_errors()));
$rows2 = array();
$rows2['name'] = 'Overhead';
while ($r2 = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC))
{
$rows2['data'][] = $r2['overhead'];
}
sqlsrv_free_stmt($getResults);
$result = array();
array_push($result,$rows1);
array_push($result,$rows2);
echo json_encode($result, JSON_NUMERIC_CHECK);
sqlsrv_close($conn);
?>
The results seem to be okay(I pasted the results into a JSON file (data.JSON) and pulled the results into highcharts)
The JSON results are not being pulled when the following code is used -
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Dynamic Chart</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div id="container" style="min-width: 155px; height: 500px; margin: 0 auto"></div>
<script>
let titleText = ' Revenue Vs Overhead'
let categoryLabels = ['Jan','Feb','Mar','Apr','May',Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
let yAxisText = 'Delta';
$(document).ready(function(){
$.ajax({
datatype: "json",
url: "data.php",
success: function(result)
{
Highcharts.chart('container', {
chart: {
type: 'line'
},
credits: {
enabled: false
},
title: {
text: titleText
},
xAxis: {
categories: categoryLabels
},
yAxis: {
min: 0,
title: {
text: yAxisText
}
},
series: result
});
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
}); //End Ajax Call
});
</script>
</body>
</html>
When I run the code I get a blank web page.
This question already has answers here:
jquery serialize and multi select dropdown
(6 answers)
Get the values of 2 HTML input tags having the same name using PHP
(4 answers)
Closed 6 years ago.
I want to change the status in the database, with a select dropdown field.
I am sending with ajax. The first row is always working, but with multiple data i cant update the second, third..etc
I tried with serialize(), but its not working.
select from database:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".allbooks").change(function(){
var allbooks = $(this).val();
var dataString = "allbooks="+allbooks;
$.ajax({
type: "POST",
data: dataString,
url: "get-data.php",
success: function(result){
$("#show").html(result);
}
});
});
});
</script>
</head>
<body>
<?php
define("HOST","localhost");
define("USER","root");
define("PASSWORD","");
define("DATABASE","hotel");
$euConn = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
$selectRooms = "SELECT * FROM proba WHERE status='inRoom'";
$resultRooms = mysqli_query($euConn,$selectRooms);
if (mysqli_num_rows($resultRooms) > 0) {
echo "<div id='reserved' align='center'>";
While ($row = mysqli_fetch_array($resultRooms)) {
echo $row[1];
echo $row[0];
?>
<select name="allbooks" id="allbooks">
<option name="years">Choose</option>
<?php
for($i=1; $i<=19; $i++)
{
echo "<option value=".$i.">".$i."</option>";
}
?>
</select><br />
<?php }
}
else
echo "<h4>nothing in the db</h4></div>";
?>
<div id="show">
</div>
</body>
</html>
and getting the results:
if(!empty($_POST["allbooks"])) {
var_dump($_POST);
$id = 2;
//echo $_POST['modelS'];
$room = $_POST['allbooks'];
$sql2 = "UPDATE proba SET room='$room' WHERE id_reservation='$id'";
$query = mysqli_query($euConn, $sql2);
var_dump($query);
}
How to change, or what would be a simple solution? Thanks for the help.
You have multiple select elements on the rendered page with the id allbooks That's wrong, IDs must be unique. You'll want to change those to a class and use $(".allbooks").change(function(){ ....
As far as sending the row id to the server with the update, you'll need to first add the row id to the select box so you can retrieve it later, something like '<select name="allbooks" class="allbooks" data-row-id="' . $row['id_reservation'] . '"> would work.
I would also recommend splitting the work up into several functions to better organize your code (classes would be even better)
It's hard to test without access to the DB, but this should do it for you. Note that I have the update function on the same page and updated the ajax url property to '' which will send the data to a new instance of the current page to handle the update.
<?php
require_once ("db_config.php");
function updateRoom($euConn, $newRoomVal, $id)
{
$stmt = $euConn->prepare("UPDATE proba SET room=? WHERE id_reservation=?");
$stmt->bind_param('ii', $newRoomVal, $id);
/* execute prepared statement */
$stmt->execute();
/* close statement and connection */
$affectedRows = mysqli_stmt_affected_rows($stmt) > 0;
$stmt->close();
return $affectedRows;
}
function getRooms($euConn)
{
$selectRooms = "SELECT * FROM proba WHERE status='inRoom'";
$resultRooms = mysqli_query($euConn,$selectRooms);
$rows = mysqli_fetch_all($resultRooms,MYSQLI_ASSOC);
return count($rows) < 1 ? '<h4>nothing in the db</h4></div>' : createSections($rows);
}
function createSections($rows)
{
$sections = [];
foreach( $rows as $row){
$options = [];
for ($i = 1; $i <= 19; $i++)
$options[] = "<option value=" . $i . ">" . $i . "</option>";
$options = implode('', $options);
$select = '<select name="allbooks" class="allbooks" data-row-id="' . $row['id_reservation'] . '"><option value="">Choose</option>' . $options . '</select><br/>';
// .. build all your other row elements here....
$section = 'some other compiled html'.$select;
$sections[]=$section;
}
return implode('', $sections);
}
$euConn = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
if(isset($_POST["allbooks"]) && $_POST["allbooks"] !='') {
$updated = updateRoom($euConn,$_POST["allbooks"],$_POST["rowId"] );
echo json_encode(['success'=>$updated]);
exit;
}
$pageSections = getRooms($euConn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".allbooks").change(function(){
var $this = $(this);
var allbooks = $this.val();
var rowId = $this.data('row-id');
var dataString = "allbooks="+allbooks+'&rowId='+rowId;
$.ajax({
type: "POST",
data: dataString,
url: "",
success: function(result){
$("#show").html(result);
}
});
});
});
</script>
</head>
<body>
<div id='reserved' align='center'>
<?php echo $pageSections ?>
<div id="show">
</div>
</body>
</html>
I am trying to run the jtable demos for php, but am always having an error that is :
"An error occured while communicating to the server".
I know that i can list the json encode , because i tried to print it, but cant get the data inside the table because of that error.
Thanks in advance
index.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Datatable with mysql</title>
<link href="themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<link href="Scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" />
<script src="scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="Scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
<div class="container">
<div class="">
<h1>jTable Demo Server Side</h1>
<div class="col-sm-8" id="employee_grid">
</div>
</div>
</div>
<script type="text/javascript">
$( document ).ready(function() {
$('#employee_grid').jtable({
title: 'List of Employees',
defaultSorting: 'Name ASC',
actions: {
listAction: 'response.php?action=list',
createAction: 'response.php?action=create',
updateAction: 'response.php?action=update',
deleteAction: 'response.php?action=delete'
},
fields: {
personID: {
title: 'EMPId',
width: '10%',
edit: false
},
name: {
title: 'Employee Name',
width: '40%'
},
age: {
title: 'Employee Salary',
width: '20%'
},
recordDate: {
title: 'Age',
width: '30%'
}
}
});
$('#employee_grid').jtable('load');
});
</script>
response.php
<?php
try
{
//Open database connection
$con = mysqli_connect('localhost', 'root', '','aaa') or die("Connection failed: " . mysqli_connect_error());
mysqli_select_db( $con,"aaa");
//Getting records (listAction)
if($_REQUEST["action"] == "list")
{
//Get records from database
$result = mysqli_query($con,"SELECT * FROM `people`;");
//Add all records to an array
$rows = array();
while($row = mysqli_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $rows;
echo json_encode($jTableResult);
}
else if($_REQUEST["action"] == "create")
{
//Insert record into database
$result = mysqli_query($con, "INSERT INTO people(Name, Age, RecordDate) VALUES('" . $_POST["Name"] . "', " . $_POST["Age"] . ",now());");
//Get last inserted record (to return to jTable)
$result = mysqli_query($con , "SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
$row = mysqli_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
//Close database connection
mysqli_close($con);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
echo json_encode($jTableResult);
}
?>
That is I cant put this demo to work.
I'm trying to do the following:
from a html page, pushing a button will call a php script which query a db and echoes json.
Php page can be found at http://vscreazioni.altervista.org/prova.php and works fine.
What doesn't work is jquery side, because I'm getting parsererror as response.
Here's my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1" />
<style type="text/css">
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#button_1').click(function(e){
e.preventDefault();
e.stopPropagation();
favfunct();
});
});
function favfunct() {
$.ajax({
type: 'GET',
url: 'prova.php',
dataType: 'json',
success: function (json) {
alert("SUCCESS!!!");
},
error: function (xhr, status) {
alert(status);
},
});
}
</script>
</head>
<body>
<input id="button_1" type="button" value="push" />
</body>
</html>
I'm totally new at this stuff...any help would be appreciated
EDIT:
php code from prova.php
<?php
$conn = mysql_connect("localhost", “username”, “passwd”);
if (!$conn)
{
mysql_close($conn);
die("Problemi nello stabilire la connessione");
}
if (!mysql_select_db("my_vscreazioni"))
{
mysql_close($conn);
die("Errore di accesso al data base utenti");
}
$queryIcostanza = "SELECT SUM(iCostanza) FROM apps";
$resultIcostanza = mysql_query($queryIcostanza) or die(mysql_error());
$rowIcostanza = mysql_fetch_array($resultIcostanza);
$queryIversi = "SELECT SUM(iVersi) FROM apps";
$resultIversi = mysql_query($queryIversi) or die(mysql_error());
$rowIversi = mysql_fetch_array($resultIversi);
$queryI10numeri = "SELECT SUM(i10Numeri) FROM apps";
$resultI10numeri = mysql_query($queryI10numeri) or die(mysql_error());
$rowI10numeri = mysql_fetch_array($resultI10numeri);
$queryIcostanza4x = "SELECT SUM(iCostanza4x) FROM apps";
$resultIcostanza4x = mysql_query($queryIcostanza4x) or die(mysql_error());
$rowIcostanza4x = mysql_fetch_array($resultIcostanza4x);
$queryOndanews = "SELECT SUM(OndaNews) FROM apps";
$resultOndanews = mysql_query($queryOndanews) or die(mysql_error());
$rowOndanews = mysql_fetch_array($resultOndanews);
$queryFarmachimica = "SELECT SUM(FarmaChimica) FROM apps";
$resultFarmachimica = mysql_query($queryFarmachimica) or die(mysql_error());
$rowFarmachimica = mysql_fetch_array($resultFarmachimica);
$queryIcarrano = "SELECT SUM(iCarrano) FROM apps";
$resultIcarrano = mysql_query($queryIcarrano) or die(mysql_error());
$rowIcarrano = mysql_fetch_array($resultIcarrano);
$totale = 0;
$totaleIcostanza = $rowIcostanza['SUM(iCostanza)'];
$totaleIversi = $rowIversi['SUM(iVersi)'];
$totaleI10numeri = $rowI10numeri['SUM(i10Numeri)'];
$totaleIcostanza4x = $rowIcostanza4x['SUM(iCostanza4x)'];
$totaleOndanews = $rowOndanews['SUM(OndaNews)'];
$totaleFarmachimica = $rowFarmachimica['SUM(FarmaChimica)'];
$totaleIcarrano = $rowIcarrano['SUM(iCarrano)'];
$totale = $totaleIcostanza + $totaleIversi + $totaleI10numeri + $totaleIcostanza4x + $totaleOndanews + $totaleFarmachimica + $totaleIcarrano;
$comando = "select * from apps";
$result = mysql_query($comando) or die(mysql_error());
$ultima_data="";
while ( $dati = mysql_fetch_assoc($result) )
{
$ultima_data = $dati['data'];
}
$response = array();
$posts = array('icostanza'=> $totaleIcostanza, 'iversi'=> $totaleIversi, 'i10numeri'=> $totaleI10numeri, 'icostanza4x'=> $totaleIcostanza4x, 'ondanews'=>$totaleOndanews, 'farmachimica'=> $totaleFarmachimica, 'icarrano'=> $totaleIcarrano, 'totale'=>$totale, 'ultimo'=>$ultima_data);
$response['posts'] = $posts;
$json = json_encode($response);
echo $json;
mysql_close($conn);
?>
Edit 2:
I was having a misspelling issue. Now I got SUCCESS!!! as reported in
success: function (json) {
alert("SUCCESS!!!");
}
how can alert json content? I tried with
alert(json);
but i get an alert with [object Object]
In success block do like following to get posts.
success: function (json) {
alert(json.posts.icostanza);
},
this will alert "icostanza" value.
I've got all my html working correctly but there seems to be a problem with my php code when i try to autocomplete a field
search.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/style.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript" src="js/jquery.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="js/script.js"></SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div class="main">
<div class="">scriptime</span></div>
<div id="holder">
Enter Keyword : <input type="text" id="keyword" tabindex="0"><img src="images/loading.gif" id="loading">
</div>
<div id="ajax_response"></div>
</div>
</body>
</html>
here my php code
names.php
<?php
include("Connections/myphp.php");
$keyword = $_POST['data'];
$sql = "select username from ".$users." where ".$username." like '".$keyword."%' limit 0,20";
//$sql = "select username from ".$users."";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result))
{
echo '<ul class="list">';
while($row = mysql_fetch_array($result))
{
$str = strtolower($row['username']);
$start = strpos($str,$keyword);
$end = similar_text($str,$keyword);
$last = substr($str,$end,strlen($str));
$first = substr($str,$start,$end);
$final = '<span class="bold">'.$first.'</span>'.$last;
echo '<li><a href=\'javascript:void(0);\'>'.$final.'</a></li>';
}
echo "</ul>";
}
else
echo 0;
?>
ajax code
/*
cc:scriptime.blogspot.in
edited by :midhun.pottmmal
*/
$(document).ready(function(){
$(document).click(function(){
$("#ajax_response").fadeOut('slow');
});
$("#keyword").focus();
var offset = $("#keyword").offset();
var width = $("#keyword").width()-2;
$("#ajax_response").css("left",offset.left);
$("#ajax_response").css("width",width);
$("#keyword").keyup(function(event){
//alert(event.keyCode);
var keyword = $("#keyword").val();
if(keyword.length)
{
if(event.keyCode != 40 && event.keyCode != 38 && event.keyCode != 13)
{
$("#loading").css("visibility","visible");
$.ajax({
type: "POST",
url: "names.php",
data: "data="+keyword,
success: function(msg){
if(msg != 0)
$("#ajax_response").fadeIn("slow").html(msg);
else
{
$("#ajax_response").fadeIn("slow");
$("#ajax_response").html('<div style="text-align:left;">No Matches Found</div>');
}
$("#loading").css("visibility","hidden");
}
});
}
else
{
switch (event.keyCode)
{
case 40:
{
found = 0;
$("li").each(function(){
if($(this).attr("class") == "selected")
found = 1;
});
if(found == 1)
{
var sel = $("li[class='selected']");
sel.next().addClass("selected");
sel.removeClass("selected");
}
else
$("li:first").addClass("selected");
}
break;
case 38:
{
found = 0;
$("li").each(function(){
if($(this).attr("class") == "selected")
found = 1;
});
if(found == 1)
{
var sel = $("li[class='selected']");
sel.prev().addClass("selected");
sel.removeClass("selected");
}
else
$("li:last").addClass("selected");
}
break;
case 13:
$("#ajax_response").fadeOut("slow");
$("#keyword").val($("li[class='selected'] a").text());
break;
}
}
}
else
$("#ajax_response").fadeOut("slow");
});
$("#ajax_response").mouseover(function(){
$(this).find("li a:first-child").mouseover(function () {
$(this).addClass("selected");
});
$(this).find("li a:first-child").mouseout(function () {
$(this).removeClass("selected");
});
$(this).find("li a:first-child").click(function () {
$("#keyword").val($(this).text());
$("#ajax_response").fadeOut("slow");
});
});
});
when i try to search a name it give me an error saying : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where like 'ben%' limit 0,20' at line 1
$sql = "select username from ".$users." where ".$username." like '".$keyword."%' limit 0,20";
you missed the $users and $username what their values are?
2 Things:
I don't think you need data:"data="+keyword, looking at your php data:keyword will suffice.
Second,
try changing your query to:
$sql = "select username from users where username like '".$keyword."%' limit 0,20";
since your php does not seem to have $users or $username set.