我有以下查询 -
$query = mysql_query("SELECT * FROM test where admin = 'Yes' order by name = '$_GET[name]' DESC");
while($row = mysql_fetch_array($query))
{
$id.=$row[id];
}
echo $id;
我想要一个从$ _GET [name]的id开始的id列表但是它返回一个列表,其下面的行的起始名称是?有任何想法吗?
非常感谢。
答案 0 :(得分:1)
使用数组
您需要在字符串名称
$query = mysql_query("SELECT * FROM test where admin = 'Yes' order by name = '$_GET[name]' DESC");
$ids = array();
while($row = mysql_fetch_array($query))
{
$ids[] =$row['id'];
}
// Your IDs are now in an array which is easier to work with
print_r($ids);
仅供参考,you shouldn't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。