为什么您不应该多次使用mysql_fetch_assoc? [英] Why you should not use mysql_fetch_assoc more than 1 time?

查看:35
本文介绍了为什么您不应该多次使用mysql_fetch_assoc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人说您不应该多次使用mysql_fetch_assoc,为什么?

Some people say you should not use mysql_fetch_assoc more than one time, why is that?

例如:我想显示两个表,一个与付费会员的用户一起显示,另一个与不付费的用户一起显示,因此我没有查询2次数据库,而是一次查询了两种类型的用户的$result变量,然后我运行循环mysql_fetch_assoc,看看是否list['membership'] = 'paid'然后回声...

e.g.: I want to display two tables one with users who paid for membership, other with users who did not, so instead of querying database 2 times I query it one time and get $result variable with both types of users then I run loop mysql_fetch_assoc and see if list['membership'] = 'paid' then echo ...

第二次,我循环循环mysql_fetch_assoc,看看是否list['membership'] = 'free'然后回显...

Second time I loop loop mysql_fetch_assoc and see if list['membership'] = 'free' then echo ...

考虑到我获得的注册和未注册用户数量相等,哪些资源使用较少?

What uses less resources considering I got about equal amount of users who registered and unregistered.

推荐答案

将您的查询结果集视为香肠,并将mysql_fetch_assoc()当作刀将香肠切成薄片.每次取一行时,都会切掉另一根香肠,它永远都是新的香肠.您不能去切掉先前切过的一块,因为它已经被吃掉了.

Think of your query result set as a sausage, and mysql_fetch_assoc() as a knife that slices off a piece of that sausage. Every time you fetch a row, another piece of sausage is cut off, and it's always a NEW piece of sausage. You can't go and cut off a previously cut piece, because it's been eaten already.

这篇关于为什么您不应该多次使用mysql_fetch_assoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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