mysql에서 PHP pdo로 데이터를 가져 오기 위해 쿼리를 실행하고 싶습니다.PHP PDO - 어디에서 선택하십시오 (입력 필드에서 값 가져 오기)
쿼리는 다음과 같이해야합니다 : 그래서 처음 SELECT * FROM akt_djubrenje where ID_akt = (I need to get value from html with ajax)...
내가 MySQL의 데이터를 가지고 : 내가 필요로하는 방법
<input id="akt_djubrenje" name="akt_djubrenje" type="text" placeholder="1" value="1" class="form-control input-md">
: 또한
CREATE TABLE IF NOT EXISTS `akt_djubrenje` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`ID_akt` int(11) NOT NULL,
`hemija` varchar(30) NOT NULL,
`kol` int(11) NOT NULL,
`jmere` varchar(5) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
내가 값을 입력 필드에 HTML이를 mysql에서 데이터를 가져 오는 경우 ID_akt = $_POST['akt_djubrenje']
그래서 이 PHP의 PDO 파일을 의식 :
또한 내가 아약스와의 PHP 파일을 호출try {
/* Establish the database connection */
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement->execute(array(':akt_djubrenje' => $_POST['akt_djubrenje']));
$result = $conn->query('SELECT * FROM akt_djubrenje where ID_akt = :akt_djubrenje"');
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'ID', 'type' => 'number'),
array('label' => 'Hemija', 'type' => 'string'),
array('label' => 'Kolicina', 'type' => 'number'),
array('label' => 'Jed.mere', 'type' => 'string')
);
foreach($result as $r) {
$temp = array();
// the following line will be used to slice the Pie chart
$temp[] = array('v' => (int) $r['ID']);
$temp[] = array('v' => (string) $r['hemija']);
$temp[] = array('v' => (int) $r['kol']);
$temp[] = array('v' => (int) $r['jmere']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo $jsonTable;
:
function tabela() {
var json = $.ajax({
url: 'getdjubrenje.php', // make this url point to the data file
dataType: 'json',
async: false
}).responseText;
var data = new google.visualization.DataTable(json);
visualization = new google.visualization.Table(document.getElementById('akt_djubrenje'));
visualization.draw(data, null);
}
그러나 나는 아무것도 얻을 해달라고?
누가 여기에서 문제가 될 수 있는지, 어떻게 해결할 수 있습니까? 나는 PHP 파일을 실행할 때
또한 내가 얻을 : Fatal error: Call to a member function execute() on a non-object in /home/agroagro/public_html/getdjubrenje.php on line 18
UPDATE : 쿼리에서 execute()
명령을 이동해야
좋아요, 그렇지만 다시 할 수 있습니다. 아무 것도 볼 수 없습니다. jquery 아약스 코드에 문제가 있습니까? – gmaestro
나는이 일을하지만 지금은 PHP 파일을 실행할 때 : 오류 : SQLSTATE [42000] : 구문 오류 또는 액세스 위반 : 1064 SQL 구문에 오류가 있습니다. 귀하의 MySQL 서버 버전에 해당하는 설명서를 확인하여 올바른 구문을 찾으십시오. 'akt_djubrenje' '1 번 근처에서 사용하십시오. – gmaestro
업데이트 된 답변을 확인하십시오. 쿼리에서 따옴표를 변경 했으므로 따옴표를 더 사용했습니다. – Fabio