将 MySQL 查询的每个单独结果分配到唯一数组的最简单方法是什么?
基本上我想在文档的其他地方调用这些变量,但我不确定最简单的方法是什么。例如,在我的具体情况下,我的查询是这样的:
$query = "SELECT report,";
$query.= "GROUP_CONCAT(DISTINCT analyst) AS analysts, ";
$query.= "GROUP_CONCAT(DISTINCT region) AS regions, ";
$query.= "GROUP_CONCAT(DISTINCT country) AS countries, ";
$query.= "GROUP_CONCAT(DISTINCT topic) AS topics, ";
$query.= "GROUP_CONCAT(DISTINCT date) AS dates, ";
$query.= "GROUP_CONCAT(DISTINCT province) AS provinces ";
$query.= "FROM reports GROUP BY report ORDER BY docID DESC ";
$result = mysql_query($query);
while($row=mysql_fetch_assoc($result)) { yada yada yada }
我希望将每个单独的 $row 保存为唯一的数组,我可以在文档中的其他位置调用它,在我的情况下,我尝试将它们称为默认值对于某些表单输入。我可以想到几种方法来做到这一点,但它们看起来都很复杂,添加一些嵌套的 for 语句,并增加 i...
有什么想法吗?
Basically I want to call these variables at other places in the document, but I am not sure what the easiest way to do this would be. For example in my specific case, my query is this:
$query = "SELECT report,";
$query.= "GROUP_CONCAT(DISTINCT analyst) AS analysts, ";
$query.= "GROUP_CONCAT(DISTINCT region) AS regions, ";
$query.= "GROUP_CONCAT(DISTINCT country) AS countries, ";
$query.= "GROUP_CONCAT(DISTINCT topic) AS topics, ";
$query.= "GROUP_CONCAT(DISTINCT date) AS dates, ";
$query.= "GROUP_CONCAT(DISTINCT province) AS provinces ";
$query.= "FROM reports GROUP BY report ORDER BY docID DESC ";
$result = mysql_query($query);
while($row=mysql_fetch_assoc($result)) { yada yada yada }
I would like to have each individual $row save as a unique array where I can call it someplace else in the document, in my case, I am trying to call them as default values for some form inputs. I can think of several ways to do this, but they all look quite involved, adding some nested for statements, and incrementing i...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Which为
您提供了一个父
$data
数组,其中的每个元素都是您获取的关联数组之一。how about
Which gives you a parent
$data
array, where each element in it is one of the associative arrays you fetched.假设每个生成的数据库行都是唯一的,每个 $row 将在内容方面是唯一的。将行粘贴到名为 $rows 的数组中,如下所示 -
如果您正在谈论将每一行命名为唯一变量,那么您可以做一些事情,但是您会留下不可预测的变量名称来尝试弄清楚,所以我希望这不是你的意思:)
Each $row will be unique, contents-wise, assuming each resulting database row is unique. Stick the rows into an array called $rows like so -
If you're talking about naming each row as a unique variable, there are things you could do, but then you're left with unpredictable variable names to try and figure out, so I'm hoping that's NOT what you mean :)