php可以查询先前查询的结果吗? [英] Can php query the results from a previous query?

查看:55
本文介绍了php可以查询先前查询的结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些语言中(想到了ColdFusion),您可以对上一个查询的结果集运行查询.可以在php中做类似的事情(以MySQL作为数据库)吗?

In some languages (ColdFusion comes to mind), you can run a query on the result set from a previous query. Is it possible to do something like that in php (with MySQL as the database)?

我有点想做

$rs1 = do_query( "SELECT * FROM animals WHERE type = 'fish'" );
$rs2 = do_query( "SELECT * FROM rs1 WHERE name = 'trout'" );

推荐答案

对于PHP,没有像这样的MySQL函数,但是有一个更高级的

There is no MySQL function like this for PHP, however there is a more advanced substitute for it.

对于那些不知道查询是什么的人来说,正是这样,并且有人这样做是有目的的.使用AND运算符是不一样的"!如果我想为脚本的一部分获取用户名="animuson"的结果,然后从状态为"1"的查询中获取所有结果,那么使用AND运算符运行另一个查询是不合逻辑的,那就是在PHP中循环遍历以前的结果要合乎逻辑.停止评论而不阅读关于为什么不首先评论它们的评论,这只是懒惰.如果您不知道所谈论的内容,那么一开始就不应该赞成或不赞成.

For those of you who don't know what a query of queries is, it's exactly this and there's a purpose some people do it like this. Using an AND operator is ****NOT**** the same thing! If I want results where username='animuson' for one part of my script and then want all the results out of that query where status='1', it is not logical for me to run another query using an AND operator, it is much more logical to loop through the previous results in PHP. Stop upvoting things without reading the comments on why they weren't upvoted in the first place, that's just lazy. If you don't have a clue what's being talked about, you shouldn't be upvoting or downvoting in the first place.

这篇关于php可以查询先前查询的结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆