跳至内容

欢迎!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

此问题已终结
作为版主,您可以批准或拒绝该答案。
接受 拒绝
38 查看

This is a <td> in PHP associated with a foreach loop.

1 is the query to select userid from the table

2 is condition to check result exist or not

3 is echo the username after finding it


Now this code exist a potential issue, that is set a initializing variable for $cobrokeusername.

Since it is a loop, system will auto retrieve the before value if the current value is empty.

Below are the example array data:

As you can see, sales8 is not associated with a user ID, so it should not echo anything. However, since the initializing variable for $cobrokeusername hasn't been set, the system will still echo the value from the previous iteration, which is the username associated with the user ID 1001.

So, the output data will be:

Action to avoid this; adding initializing variable to it

After setting the initializing variable, each loop iteration will run with this value, which is an empty value for $cobrokeusername.

Now, the system will be able to get the correct data inside the loop.


Summary:

When you want to output different values inside the loop, it is important to add the initializing variable to the value to avoid the issue of retaining previous values.

形象
丢弃

您的回复

请大家尽量给个实质性的回答。如果您想回答这个问题或发表评论,只需 使用评论工具。请记住,您可以随时修改您的答案。 - 不用重复回答同样的问题。另外,请不要忘记投票 - 它确实有助于选择最好的问题和答案!

相关帖文 回复 查看 活动
0
2月 25
54
0
2月 25
45
0
1月 25
42
0
1月 25
57
0
3月 25
30