2015-09-18 410 views
0

我在我的應用程序中填充List。在另一個Activity中,我試圖讓每個「事件」在ListView中顯示。因此,我設立了一個EditText,讓我進入一個城市,例如「漢堡」。點擊確認按鈕後,該列表應顯示在漢堡的所有事件。從MySQL中選擇

+---------+----------+----------+------------------+ 
| user_id | name | location | description | 
+---------+----------+----------+------------------+ 
|  5 | Dinner | Hamburg | With the Family | 
|  6 | Marriage | Bremen | Alex and Sabrina | 
|  7 | Match | Berlin | Hamburg - Hertha | 
|  8 | Meeting | Berlin | Alexanderplatz | 
|  9 | Cinema | Berlin | FUG2    | 
+---------+----------+----------+------------------+ 

我的問題,我想不出如何聲明PHP文檔中的SQL語句。所有我擁有的是:

$result = mysql_query("SELECT * FROM events WHERE location = ':location'") or die(mysql_error()); 

enter image description here

+0

刪除 ':位置' 單引號和檢查 – rajuGT

+1

你在哪裏設置':location'? –

+0

糾正我,如果我錯了,但'mysql_ *'甚至有參數化的查詢支持? –

回答

0

如果您提交數據到PHP文件,那麼你可以使用像這樣的位置:

$location=$_POST['location']; 
$result = mysql_query("SELECT * FROM events WHERE location = $location") or die(mysql_error()); 
0
$result = mysql_query("SELECT * FROM events WHERE location = $location") 
3

mysql_功能depricated。我不認爲原始的mysql擴展支持命名參數。你真的應該看看mysqli甚至更​​好PDO

在mysqli的,將是這樣的:

$mysqli = new mysqli("localhost", "root", "password", "database"); 
$sql = "SELECT * FROM events WHERE location = ?"; 
$statement = $mysqli->prepare($sql); 
$statement->bind_param("s", $location); 
$statement->execute(); 
+0

好的,謝謝。 – Dominik