我可能会遇到错误的方向,但我想从数据库中获取数据数组,然后在另一个SQL语句中使用该数组。如何在sql语句中使用sql数据库中的数组
这里是我当前的代码:
$result = mysql_query($query_friend_club_count) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$row['idPerson']. " - ". $row['idFriend'];
$idFriend = $row['idFriend'];
$array = $idFriend',';
$query_friends = "SELECT * FROM whosout WHERE idPerson IN ('$array')";
$query_friends_run = mysql_query($query_friends);
$friendCounter = mysql_num_rows($query_friends_run);
echo $friendCounter;
}
我得到的错误:
syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
不知道有没有什么帮助。
任何建议将是非常有帮助的,因为我一直坚持这个年龄!第一,而不是每个quering他们
$array = $idFriend . ','; //There should be a period here.
你在同一个数据库中查询的两张表是?这看起来应该是一个带JOIN的单个查询,而不是围绕构建数组和执行多个查询。另外,第二个查询是否应该在* while循环中? – 2014-09-30 14:55:30
你能告诉我们'$ query_friend_club_count'是什么吗? – 2014-09-30 14:58:06
请[不要在新代码中使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 *他们不再维护,并[已正式弃用](https://wiki.php.net/rfc/mysql_deprecation)*。看到[红色框](http://uk.php.net/manual/en/function.mysql-connect.php)?学习[准备的语句](http://en.wikipedia.org/wiki/Prepared_statement),并使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。 [这篇文章](http://php.net/manual/en/mysqlinfo.api.choosing.php)将帮助你决定哪些。 – 2014-09-30 14:59:39