foreach

Mysql Foreach Child show Max() and Min() in a single line.

Is it possible to use a select statement so that it returns Max and min columns of a child row foreach Parent record? So foreach parent record that has MANY child records I want to see the Max and Min of those child records for any given column. How can I do this within a single select statement? It should read something like: Return ...

Does a foreach loop copy each item of an IEnumerable while iterating?

I have a foreach loop like below foreach (XYZ split in this.splits ) { // this code is inserted for debug purpose only bool check = object.ReferenceEquals(splits.First(), split); ..... } When I have single element in this.splits, check is returning false. I have checked by so...

Sort order of C# for each loop

I was wondering about the order that a foreach loop in C# loops through a System.Collections.Generic.List object. I found another question about the same topic, but I do not feel that it answers my question to my satisfaction. Someone states that no order is defined. But as someone else states, the order it traverses an array is fixed ...

Returning a match from a List<KeyValuePair<string,string>>

Hello, I currently have a class that uses the KeyValuePair with List to store a collection of tracks in the format of Key = track, Value = artist. I'm trying to provide a way of searching for a particular track and if there are any matches then return the entire matching CD. This is my attempt so far: public CompilationCD FindTrackIn...

How to display two table columns per row in php loop

Hi, I would like to display data, two columns per row during my foreach. I would like my result to look like the following: <table> <tr><td>VALUE1</td><td>VALUE2</td></tr> <tr><td>VALUE3</td><td>VALUE4</td></tr> <tr><td>VALUE5</td><td>VALUE6</td></tr> </table> Any help would be greatly appreciated. Thanks ...

Php explode then get the name row from a MySql Table

I know this has been talked about here before. However, my situation is a bit different and I'm so close. I would like to explode an array of category id's from a news data table then get the category name from the category table. Right now I am able to get the id's out and explode them just fine inside the while loop for the news da...

Modifying contents of vector in BOOST_FOREACH

This is a question that goes to how BOOST_FOREACH checks it's loop termination cout << "Testing BOOST_FOREACH" << endl; vector<int> numbers; numbers.reserve(8); numbers.push_back(1); numbers.push_back(2); numbers.push_back(3); cout << "capacity = " << numbers.capacity() << endl; BOOST_FOREACH(int elem, numbers) { cout << elem << end...

PHP foreach glob to load images from a folder not working quite right

Hi, I need to load images from 2 different folders, each thumbnail has its associated large version (same name, different folder). I have 3 files in the large pics folder and 3 files in the thumbs folder and I'm getting 9 links! Each thumbnail gets repeated 3 times or x times the quantity of pics in the main folder This is the code: <?...

C++: Iterating through a vector of vectors

Hey there! I'm doing this project and right now I'm trying to: create some of objects and store them in vectors, which get stored in another vector V iterate through the vectors inside V iterate through the objects inside the individual vectors Anyway, I was just searching the web and I came accross the stl for_each function. It seem...

Insert multiple rows into mysql with php using foreach arrays

Im stuck, been trying to figure this out for 2 hours now. I have figured out the foreach loop, but cant figure out how to insert the data now. here is my php, what am I doing wrong? $query = "INSERT INTO images (thumb_path, image_path, main_image, project_id) VALUES "; foreach($_POST as $key => $value) { $query .= "$thumb_pat...

Java foreach loop: for (Integer i : list) { ... }

when i use jdk5 like below ArrayList<Integer> list = new ArrayList<Integer>(); for (Integer i : list) { //cannot check if already reached last item } on the other hand if i just use iterator ArrayList<Integer> list = new ArrayList<Integer>(); for (Iterator i = list.iterator(); i.hasNext();) { //i can ...

Erlang : Breaking out of lists:foreach "loop"

I have a list of elements in Erlang, and I'm using lists:foreach to traverse through the elements in the list. Is there a way to break out of this "foreach loop" in the middle of the traversal. For eg: suppose I want to stop traversing the list further if I encounter a '1' in the list [2, 4, 5, 1, 2, 5]. How do I do this? ...

For-Each and Pointers in Java

Ok, so I'm tyring to iterate through an ArrayList and remove a specefic element. However, I am having some trouble using the For-Each like structure. When I run the following code: ArrayList<String> arr = new ArrayList<String>(); //... fill with some values (doesn't really matter) for(String t : arr) { t = " some other value "; //hop...

Better way of searching through lists than using foreach

list vclAsset<FullAsset> list callsigns<string> foreach(FullAsset fa in vclAsset) { if (callsigns.contains(fa.asset.callsign)) { //do something } } Is there a more elegant way to do the above? A FullAsset object contains an Asset object which in turn has a string "Callsign." Each callsign will be unique, so my li...

Access Enumerator within a foreach loop?

I have a List class, and I would like to override GetEnumerator() to return my own Enumerator class. This Enumerator class would have two additional properties that would be updated as the Enumerator is used. For simplicity (this isn't the exact business case), let's say those properties were CurrentIndex and RunningTotal. I could mana...

PHP adding leading 0 to range

How do I have it render leading 0's for 1-9 ? <?php foreach (range(1, 12) as $month): ?> <option value="<?=$month?>"><?=$month?></option> <?php endforeach?> ...

PHP foreach loop key value

I am running this DB call to get me multi-dimensional array I am trying to get the keys of each but when I try it comes up blank or as array. $root_array = array(); $sites = $this->sites($member_id); foreach ($sites as $site){ $records = $this->db->select('p.name as place_name, p.id as place_id,p.active a...

EXSLT func:return problems in xsl:for-each "loop" and func:function

My problem: I have a wealth of atom RSS feed files which have many different atom entries in them and a few overlapping entries between files. I need to find and return an entry based on a URL from any one of the RSS feeds. Technologies: This code is being run through PHP 5.2.10's XLSTProcessor extension, which uses XSLT 1, has support ...

Combining multiple expressions (Expression<Func<T,bool>>) not working with variables. Why?

ok guys, bare with me. I'll summarize first, then go into detail. I've written a number of methods (.WhereOr, .WhereAnd) which basically allow me to "stack up" a bunch of lambda queries, and then apply them to a collection. For example, the usage with datasets would be a little like this (although it works with any class by using generi...

replace a simple forloop with linq

Hello everyone, I want to know how to replace a simple foreach loop with linq. I'm not looking for answers about 2 or more loops....It's specifically for a single foreach loop.. List<string> strlist=new List<string>(); strlist.Add("Hello"); strlist.Add("World"); //The main "to be linq" here... foreach(string str in strlist) { Cons...