我見過很多教程,但他們很混亂,做我想做的事情,我只是沒有得到如何使用從這些教程中獲得現有的東西,並使它們按我希望的方式工作。通過PHP(jQuery/AJAX)從MySQL獲取到jquery(mobil應用程序)
我有一個圖標@ homepage。當用戶點擊時,我想要做一個查詢「select * from tablename」,並將結果顯示在特定的div中。
有人可以告訴我這是如何實現的嗎?只是一件非常基本的事情就是讓我開始。任何幫助表示讚賞。
謝謝。
我見過很多教程,但他們很混亂,做我想做的事情,我只是沒有得到如何使用從這些教程中獲得現有的東西,並使它們按我希望的方式工作。通過PHP(jQuery/AJAX)從MySQL獲取到jquery(mobil應用程序)
我有一個圖標@ homepage。當用戶點擊時,我想要做一個查詢「select * from tablename」,並將結果顯示在特定的div中。
有人可以告訴我這是如何實現的嗎?只是一件非常基本的事情就是讓我開始。任何幫助表示讚賞。
謝謝。
文檔幾乎解釋了它的自我:http://www.php.net/manual/en/mysqli.construct.phphttp://www.php.net/manual/en/mysqli.query.php
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$result = $mysqli->query("SELECT 1;");
while(($row = $result->fetch_assoc()) != NULL) {
//use rows
}
$mysqli->close();
<html>
<head>
<script type="text/JavaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/JavaScript">
$(function() {
$("#buttonId#).click(function() {
$("#divToUpdate").load("/scriptPhp.php");
});
</script>
</head>
<body>
<input id="buttonId" type="button" value="click me!" />
<br />
<div id="divToUpdate">
</div>
</body>
</html>
而在你scriptPHP.php文件:
<table>
<thead>
<tr>
<th>Cell 1</th>
<th>Cell 2</th>
</tr>
</thead>
<tbody>
<?php
$pdo = new Pdo("mysql:host=localhost;dbname=nameOfTheDatabase;charset=utf8", "username", "password");
$rows = $pdo->query("SELECT * FROM tablename")->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
?>
<tr>
<td><?php echo $row['cell_1']; ?></td>
<td><?php echo $row['cell_2']; ?></td>
</tr>
<?php
}
?>
</table>
你嘗試過這麼遠嗎?你卡在哪裏?你有什麼特別的問題嗎? – brbcoding 2013-03-08 20:12:54
我建議在發佈問題前閱讀常見問題解答。 – 2013-03-08 20:13:05
我討厭每次都問,你有沒有嘗試過,請發帖 – Rafay 2013-03-08 20:13:55