foreach

help with php FOREACH loop

hi, can some please tell me what's wrong with the bellow foreach php loop. foreach ($_POST[sortlist] as $key => $value) { $sql = "UPDATE sortable SET color_order = " . mysql_real_escape_string($key) . " WHERE id = " . mysql_real_escape_string($value); $result = mysql_query($sql) or die(mysql_error());...

looping through a object which contains an object php

I have a PHP Object which contains other objects i.e $obj->sec_obj->some_var; I want to use a foreach loop to loop through the object and all objects objects. I think the max level is 3, so $obj->sec_obj->third_obj->fourth_obj Any ideas? ...

Challenge: C# Foreach - Before, After, Even, Odd, Last, First

Since C# doesn't have a before,after,last,first etc. as part of its foreach. The challenge is to mimic this behavior as elegantly as possible with the following criteria: Must allow: before, first, even, odd, last, after events Give an option execute/not execute the primary function (function executed on all objects of the collection) ...

Changing the BackColor of my custom UserControl - help!

Hello my kind sirs. (lol) I have a panel on Form1. I'm going to add several instances of my custom usercontrol MovieItem to that panel. To do this I'm going: panel1.Controls.Add(objMovieItem); Now, within the MovieItem.cs code I'm adding the .Click events of everything inside the UserControl so that whenever a user clicks ANYWHERE i...

Question about foreach and delegates

Suppose the following code: foreach(Item i on ItemCollection) { Something s = new Something(); s.EventX += delegate { ProcessItem(i); }; SomethingCollection.Add(s); } Of course, this is wrong because all the delegates points to the same Item. The alternative is: foreach(Item i on ItemCollection) { Item tmpItem = i; Som...

QT: why is foreach iterating with a const reference ?

I try to do the following: QList<QString> a; foreach(QString& s, a) { s += "s"; } Which looks like it should be legitimate but I end up with an error complaining that it cannot convert from 'const QString' to 'QString &'. Why is the QT foreach iterating with a const reference? ...

Assigning parameter value to the xsl: for each..

Hi All, Can anybody who has worked on XSLT help me on this? I am using XSL version 1.0. I have declared a parameter in XSL file like: <xsl:param name="HDISageHelpPath"/> Now I am assigning the value to this parameter from an asp page . The value which I assign is "document('../ChannelData/Sage/help/ic/xml/HDI.xml')/HelpFiles/Help"....

How can I use a foreach loop to delete all of the control in a panel?

Here's the code I have: private void ClearSearchResults() { foreach (Control X in panel1.Controls) { panel1.Controls.Remove(X); } } The problem is, when I run this method, only a single item is deleted, then if I click on a button again so the method can run again, another is deleted. If I ...

Update Struct in foreach loop in C#

I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing { public string Name; } class Program { static void Main(string[] args) { List<Thing> things = new List<Thing>(); foreach (Thing t in things) // for each fil...

Dynamic typing of foreach variable.

In the following code, How can I pass the type of variable to the nested foreach statement? getControls is a recursive function that returns a list of controls (wow!) getControls(String type, Control donde) var tipos = new List<Type>() { typeof(Button), typeof(KryptonTextBox) }; foreach (Type t in tipos) { List<Control> controls ...

In a java enhanced for loop, is it safe to assume the expression to be looped over will be evaluated only once?

Hi, In Java, a for-each loop. If I have a method that generates an array, called genArray(). In the following code, will the array each time be re-generated by calling genArray()? Or will Java call once the method and store a copy from the array? for (String s : genArray()) { //... } Thanks ...

.net - For Each Obj as MyObject in MyArray -- Is this doable without implementing anything?

I'm using VS2008. Is the following OK to do the following VB.NET with a very simple class (see below)? for each CurrentObject as MyObject in MyArray 'access current object next The "simple class": Class MyObject public I as integer end class I seem to remember that something about needing iEnumerable, but my compiler isn't com...

How do I apply templates to each selected node in a for-each?

I know I'm missing something here. In the XSLT transformation below, the actual result doesn't match the desired result. Inside the for-each, I want to apply the match="track" template to each selected track element. If I've understood XSLT properly, with the current setup only child nodes of each selected track element are matched agai...

How to write a class capable of foreach

It's been a while since Visual Studio added support for a foreach extension that works like vector<int> v(3) for each (int i in v) { printf("%d\n",i); } I want to know how to make any class able to use foreach. Do I need to implement some interface? ...

How does foreach work when looping through function results?

Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some stuff } Will someObj.GetMyStrings() be called on every iteration of the loop? Would it be better to do the following instead: List<string> myStrings = someObj.GetMyStrings(); foreach(string str in myStrings) { // do some stuff } ? ...

How to nest xsl:for-each selec

HI! My XML: <?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited by XMLSpy® --> <Dokument> <Skupina id="3"> <Naziv_skupine>RAZSTAVNI PROSTOR</Naziv_skupine> <Dvorana id="295"> <Naziv_dvorane>DVORANA C</Naziv_dvorane> <Postavka id="41"> <Artikel>1105</Artikel> </Postavka> ...

.net 3.5 anonymous foreach

I'm trying to loop through the results of a function that is returning an anonymous object of results. public static object getLogoNav() { XDocument loaded = XDocument.Load(HttpContext.Current.Request.MapPath("~/App_Data/LOGO_NAV_LINKS.xml")); var query = from x in loaded.Elements().Elements() select new ...

for-each no results text

I have a for-each and when there is nothing output by it I would like to display some default text. If I have... <xsl:for-each select='xpath'> Some content for each matching element result. </xsl:for-each> What I would like is: <xsl:for-each select='xpath'> <xsl:output-this-when-there-is-content> Some content for each matching el...

Array a string in the following format?

How can i array a string, in the format that $_POST does... kind of, well i have this kind of format coming in: 101=1&2020=2&303=3 (Incase your wondering, its the result of jQuery Sortable Serialize... I want to run an SQL statement to update a field with the RIGHT side of the = sign, where its the left side of the equal sign? I know ...

foreach no match -C shell script

I’m trying to write my first script to search for a given pattern in text file named test. Here is the script: #! /bin/csh echo -n "enter pattern: " set pattern = $< foreach word (`cat test`) echo $word | egrep $pattern end When I try to run it I get the message foreach: No match found. I suspect the problem is ca...