473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Nesting foreach loops

348 100+
Hello everyone,

I need some help and direction with this code. I am trying to have the same functionality that this forum has with regard to the allowable length of time the post (Or in my case, report) can be edited or deleted.


Here is what I have so far:

[PHP]foreach($reports as $report)
{
$final[] = $report;

foreach($buttons as $button)
{
if($button['report_id'] == $report['report_id'])
{
$final[] = "buttons";
}
}
}[/PHP]
This outer loop gets all reports and then if the post is less than 1 hour old, places an edit and delete button in the html for that particular report. (Second loop)

I have 3 files here. The first one is the class which has the sql and returns the results. The second is the body.php file which is where I have the calls to the db and any other stuff I need. I then have the html that gets populated with the results. I simply include() the html in the body.php file and then use any variables inside the html to populate the data.

What I need is to display the results from my foreach loops. Should I use this loop in the body.php or inside of the html file? I was thinking about leaving it inside the body.php file and just using $final inside the html file. would this correct?

Also, I am having an issue with the $final array. I can't seem to get the button to show.

Thanks,

Frank
Sep 7 '08 #1
2 1716
fjm
348 100+
Well, here is what I have decided to do. It works but I am not sure if this is correct or not. What I am going for here is to seperate the application code from the view.

I decided to put the code I posted above into the html file using alternate syntax. Again, the html file is an include() in the body.php file. Would this be correct? Even though it works, I am looking for proper way of doing this.

Thanks,

Frank
Sep 7 '08 #2
Dormilich
8,658 Expert Mod 8TB
what do the $button, $report and $final arrays contain? is $reports a 2D-array? what is $final supposed to contain? If you're not sure, what the arrays contain, check it with var_dump(), maybe this is giving you a hint what's wrong.

as for the files, I'd leave the processing in body.php but this depends on what the actual files look like, both ways may suffice.

regards
Sep 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Randell D. | last post by:
Folks, Ever since reading an interesting article in Linux Format on PHP whereby suggested code writing was made that could enhance performance on a server, I've started testing various bits of...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
8
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
7
by: Phil | last post by:
Hi, I read somewhere that the new version (v1.1) has improved the performance of 'foreach' over 'for'. Is that true? I did some measurements and I still think for has an upperhand... ? Phil
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
25
by: bweaverusenet | last post by:
Hi. I am trying to get some javascript to work in IE6, from the address line. It works in Firefox and, I believe, IE7. It appears that with some number of nested structures, the code does not...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
7
by: Osiris | last post by:
Just something I would like to share: I just learned the hard way (2 days detective work on a bug) that foreach loops are not at all like for loops, not intuitive at all. BEWARE: arrays and...
3
by: JonB | last post by:
The examples I'm generally finding on the web of how to do nested loops are confusing and extremely scarce. Here's what I'm trying to do... I have an array named $data that I believe qualifies as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.