我需要一个嵌套的foreach循环来执行此操作吗?救命... [英] Do I need a nested foreach loop to do this? Help...

查看:63
本文介绍了我需要一个嵌套的foreach循环来执行此操作吗?救命...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,周日快乐。 :)


我有一个问题,我认为*我可能知道解决方案,但不知道如何为它编写代码。我正在创建一个模板系统,我已经创建了一个模板html文件。我正在使用str_replace来替换我想要更改的字段。我也不确定我是否正确这样做。下面是一个代码示例。


我有一个脚本可以从数据库中提取单个客户。提取的数据是公司名称和该公司的其他详细信息,如电话号码等。由于客户有许多不同的电话号码,我的客户名称重复次数与电话号码一样多。这正是db应该做的事情,但我需要以某种方式使用php来回显公司名称,然后循环所有的电话号码,以及与该客户截然不同的地址。

Hello everyone and happy Sunday. :)

I have a problem that I *think* I may know the solution to but have no idea how to write the code for it. I am working on a templating system wher I have created a template html file. I am using str_replace to replace the fields that I want changed. I''m not sure that I am doing this correctly either. A code sample follows.

I have a script that pulls a single customer from the database. The data that is pulled is the name of the company and other details about that company such as phone numbers, etc. Since a customer has many different phone numbers, I am getting the customer name repeated as many times as are phone numbers. This is exactly what the db should be doing but I need to somehow use php to echo the company name once and then loop all of the phone numbers, and addresses that are distinct to that customer.

展开 | 选择 | Wrap | 行号

推荐答案

我暂时休息一下,想想我可能已经想到了答案。我在想:


[PHP]

foreach(
I have taken a break from this for a while and think I may have thought of the answer. I am thinking:

[PHP]
foreach(


a as


b){

echo
b){
echo


这篇关于我需要一个嵌套的foreach循环来执行此操作吗?救命...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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