2015-09-18 184 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