รบกวนหน่อยค่ะ อยากเอาค่า division ไป where ใน Sql
พอเอาไป where กลับ error
Warning: odbc_exec() [
function.odbc-exec
]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'di'., SQL state 37000 in SQLExecDirect in มีวิธีมั้ยคะ หรือคำแนะนำมั้ยคะ
Code (PHP)
<?php
$division = "<div id='di'></div>";
$sqlsec = $conn->Selectrecordjoin("select * FROM categories where group_sec = '$division' ");
$rowsec = $conn->parseArray($sqlsec);
$rowsec['name'];
?>
<script>
$(document).ready(function(){
$("#select2").select2({
ajax: {
url: 'selectdata.php',
dataType: 'json',
type: "POST",
delay: 250,
data: function (params) {
return {
term: params.term
};
},
processResults: function (data) {
return {
results: data
};
}
},
});
});
function myFunction() {
var x = document.getElementById("select2").value;
document.getElementById('di').innerHTML = x;
}
Tag : PHP, Ms SQL Server 2008, HTML, JavaScript, Ajax, jQuery
if(!isset($_POST['term'])){
$Data_sql= $conn->Selectrecordjoin("select TOP (5) PERCENT * FROM T_data order by id asc ");
}else{
$search = $conn->converttoutf8($_POST['term']);
$Data_sql= $conn->Selectrecordjoin("select * FROM T_data where Pri Like '%$search%' ");
}
$data = array();
while ($row = $conn->parseArray($Data)) {
$Section = $conn->converttotis620($row['Section']);
$data[] = array("id"=>$row['sec'],"text"=>$Section,"name"=>$row['divi']);
}
echo json_encode($data);
Code (PHP)
index.php
// $division = '<div id="di"></div>';
$division = isset($_POST['term']) ? $_POST['term'] : "";
$sqlsec = "select * from help_categories WHERE group_sec = '$division' ";
$querysec = odbc_exec($link,$sqlsec);
$rowsec = odbc_fetch_array($querysec);
echo $rowsec['name'];
<script>
$(document).ready(function(){
$("#category2").select2({
ajax: {
url: 'get.php',
dataType: 'json',
type: "POST",
delay: 250,
data: function (params) {
return {
term: params.term
};
},
processResults: function (data) {
return {
results: data
};
}
},
});
});
function myFunction() {
var x = document.getElementById("category2").value;
document.getElementById('di').innerHTML = x;
}
</script>