请问这个可以循环吗?
while(!!$_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)){
循环语句1
while(!!$_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)){
循环语句2
}
}
假设单个循环语句1要执行x次,单个循环语句2要执行y次
请问执行过程是不是先执行循环语句1一次,然后进入循环语句2进行循环直至结束,然后再回到循环语句1的循环体,再接着执行循环语句1,然后再次进入循环语句2的循环进行循环直至结束,大家能懂我意思吗?循环语句2总共执行了x*y次
我不知道是不是写错了,实际效果是循环语句2的整个循环过程只循环了y次
回复讨论(解决方案)
mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。
可是重新进入第二个while不是会重新执行mysql_fetch_array() 吗?
二重循环的算法时间复杂度为 O(n*n)
即内层循环体将执行 n(外层)* n(内层)次
不过你的嵌套循环是多余的,因为你都是对同一资源($_show_repost)进行循环
所以外层会执行一次,内层会执行n-1次
while(!!$_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)){
循环语句1
while(!!$_rerows = mysql_fetch_array($_show_rerepost,MYSQL_ASSOC)){
循环语句2
}
}
不好意思各位楼上代码写错了,是查询2个不同的
二重循环的算法时间复杂度为 O(n*n)
即内层循环体将执行 n(外层)* n(内层)次
不过你的嵌套循环是多余的,因为你都是对同一资源($_show_repost)进行循环
所以外层会执行一次,内层会执行n-1次
不好意思之前写错了,里面那个查询的是另外一个
那么内层的 $_show_rerepost 需要重新查询或回绕
那么内层的 $_show_rerepost 需要重新查询或回绕
版主那是不是这样循环就不能实现?有什么实现的好方法吗
我都不知道你打算做什么?能有什么好方法
就是我在数据库建了2个表,一个是回帖信息,一个是对回帖的回复,循环语句1就是先一个一个输出回帖,循环语句2(里面有if语句判定)就是假如在这个回帖有对回帖的回复,就输出对回帖的回复内容,我想实现的效果是输出一条回帖,底下如果有别人回复这个回帖就显示回复,然后循环输出下个回帖,就和百度贴吧回复功能类似
表一 回帖信息
表二 回帖的回复
所以表二中必有一字段指向表一的id,假设为 fid
于是有
$_show_repost = mysql_query('select * from 表一');
where($_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)) {
$_show_rerepost = mysql_query("select * from 表二 where 表二.fid=$_rerows[id]");
while(!!$_rerows = mysql_fetch_array($_show_rerepost,MYSQL_ASSOC)){
}
}
表一 回帖信息
表二 回帖的回复
所以表二中必有一字段指向表一的id,假设为 fid
于是有
$_show_repost = mysql_query('select * from 表一');
where($_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)) {
$_show_rerepost = mysql_query("select * from 表二 where 表二.fid=$_rerows[id]");
while(!!$_rerows = mysql_fetch_array($_show_rerepost,MYSQL_ASSOC)){
}
}
嗯,我会继续努力的,感谢斑竹大大

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.
