从 SQL COUNT() 和 GROUP BY 获取 PHP 变量及其值
我试图从测试中的“思维技能”(如分析、评估等)中提取并生成变量,并将其值设置为每个测试项目的数量。我被困住了,所以任何帮助将不胜感激。 (SQL 语句似乎工作正常。)
我想要的示例:$analyzing = 7、$applying = 13 等...谢谢!
$sql = "SELECT thinkskill AS tskill
, COUNT(thinkskill) AS counttskill
FROM $c_keytable
GROUP BY thinkskill
ORDER BY thinkskill" ;
$result = mysql_query ( $sql ) ;
while ( $row = mysql_fetch_assoc ( $result ) )
{
// Example: $analyzing = 7 -->
${$row["tskill"]} = $row["counttskill"] ;
}
I'm trying to extract and make variables out of the "thinking skills" (like analyzing, evaluating, etc.) from a test and set their value to the number of test items within each. I'm stuck, so any help would be appreciated. (The SQL statement seems to work fine.)
Example of what I want: $analyzing = 7, $applying = 13, etc.... Thanks!
$sql = "SELECT thinkskill AS tskill
, COUNT(thinkskill) AS counttskill
FROM $c_keytable
GROUP BY thinkskill
ORDER BY thinkskill" ;
$result = mysql_query ( $sql ) ;
while ( $row = mysql_fetch_assoc ( $result ) )
{
// Example: $analyzing = 7 -->
${$row["tskill"]} = $row["counttskill"] ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
我不推荐它,但如果你真的想要将信息从数组中取出并放入局部变量中,你可以这样做
Try this:
I don't recommend it, but if you really want the info out of the array and into local variables, you can do