Search Results

Search found 4868 results on 195 pages for 'foreach'.

Page 6/195 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • How to use a dynamic smarty variable in foreach loop

    - by P Kumar
    Hi, Can anyone tell me how to use dynamic variables in smarty foreach loop. I am trying to create a module in prestashop and m very close to get it done. here's my code: //file name index.php foreach($subCategories as $s) { $foo = intval($s['id_category']); $k = new Category($foo); $var1 = "subSubCategories.$foo"; $var1 = $k-getSubCategories(1); $smarty-assign(array('foo'.$foo = $var1)); } //file name:index.tpl {assign var=foo value=$foo$cat} //where $cat is a variable that counts the number of categories {if isset($foo) AND $foo} {foreach from=$foo item=subCategories name=homesubCategories} <p>{$subCategories.name}</p> {/foreach} {else} <p>{l s='test failed'}</p> {/if} I've exhausted all of my resources and knowledge and feeling quite helpless at this moment. so plz help me out.

    Read the article

  • Foreach/For loop alternative lambda function?

    - by mamu
    We use for or foreach to loop through collections and process each entries. Is there any alternative in all those new lambda functions for collections in C#? Traditional way of doing foreach(var v in vs) { Console.write(v); } Is there anything like? vs.foreach(v => console.write(v))

    Read the article

  • Smarty - foreach loop 4 times and create a new list

    - by Harold
    I want to achieve a list like this with smarty. <ul> <li> <a>img1</a> <a>img2</a> <a>img3</a> <a>img4</a> </li> <li> <a>img5</a> <a>img6</a> <a>img7</a> <a>img8</a> </li> <li> <a>img9</a> <a>img10</a> <a>img11</a> <a>img12</a> </li> </ul> Using this sample code <ul class="bullet"> {foreach from=$manufacturers item=manufacturer name=manufacturer_list} {if $smarty.foreach.manufacturer_list.index < 4} <li class="{if $smarty.foreach.manufacturer_list.last}last_item{elseif $smarty.foreach.manufacturer_list.first}first_item{else}item{/if}"> <a href="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)}" title="{l s='More about' mod='blockmanufacturer'}{$manufacturer.name}"> <img src="{$img_manu_dir}{$manufacturer.id_manufacturer}.jpg"><span>{$manufacturer.name}<span></a> </li> {/if} {/foreach} First with given array $manufacturers it will loop inside a <li> max of 4 times and will create 4 <img>. And then, when it reach the 4th index, it will make a new <li> tag. Thanks for the help!

    Read the article

  • How to best do foreach together with count in excel

    - by user3682637
    I have been trying to do some work in excel, but i seem to be stuck on one point in colum "A" i have: a, b, c, d, e in colum "B" i have: done, started, completed in colum "C" to colum "S" i have: some "X"'s but not in all fields. So my question is how do i do the following foreach row in excel.A Where Bx is done count("X", $row) I have tried pivot, countif, sumproduct but i cant seem to get it to work, any ideas?

    Read the article

  • .NET 4 ... Parallel.ForEach() question

    - by CirrusFlyer
    I understand that the new TPL (Task Parallel Library) has implemented the Parallel.ForEach() such that it works with "expressed parallelism." Meaning, it does not guarantee that your delegates will run in multiple threads, but rather it checks to see if the host platform has multiple cores, and if true, only then does it distribute the work across the cores (essentially 1 thread per core). If the host system does not have multiple cores (getting harder and harder to find such a computer) then it will run your code sequenceally like a "regular" foreach loop would. Pretty cool stuff, frankly. Normally I would do something like the following to place my long running operation on a background thread from the ThreadPool: ThreadPool.QueueUserWorkItem( new WaitCallback(targetMethod), new Object2PassIn() ); In a situation whereby the host computer only has a single core does the TPL's Parallel.ForEach() automatically place the invocation on a background thread? Or, should I manaully invoke any TPL calls from a background thead so that if I am executing from a single core computer at least that logic will be off of the GUI's dispatching thread? My concern is if I leave the TPL in charge of all this I want to ensure if it determines it's a single core box that it still marshalls the code that's inside of the Parallel.ForEach() loop on to a background thread like I would have done, so as to not block my GUI. Thanks for any thoughts or advice you may have ...

    Read the article

  • Razor - Unexpected "foreach" keyword after "@" character

    - by Jaco Pretorius
    I have a partial view done in razor. When I run it I get the following error - it seems like Razor gets stuck into thinking I'm writing code everywhere. Unexpected "foreach" keyword after "@" character. Once inside code, you do not need to prefix constructs like "foreach" with "@" Here is my view @model IEnumerable<SomeModel> <div> @using(Html.BeginForm("Update", "UserManagement", FormMethod.Post)) { @Html.Hidden("UserId", ViewBag.UserId) @foreach(var link in Model) { if(link.Linked) { <input type="checkbox" name="userLinks" value="@link.Id" checked="checked" />@link.Description<br /> } else { <input type="checkbox" name="userLinks" value="@link.Id" />@link.Description<br /> } } } </div>

    Read the article

  • How do I delete multiple rows in Entity Framework (without foreach)

    - by Jon Galloway
    I'm deleting several items from a table using Entity Framework. There isn't a foreign key / parent object so I can't handle this with OnDeleteCascade. Right now I'm doing this: var widgets = context.Widgets .Where(w => w.WidgetId == widgetId); foreach (Widget widget in widgets) { context.Widgets.DeleteObject(widget); } context.SaveChanges(); It works but the foreach bugs me. I'm using EF4 but I don't want to execute SQL. I just want to make sure I'm not missing anything - this is as good as it gets, right? I can abstract it with an extension method or helper, but somewhere we're still going to be doing a foreach, right?

    Read the article

  • Does Parallel.ForEach require AsParallel()

    - by dkackman
    ParallelEnumerable has a static member AsParallel. If I have an IEnumerable<T> and want to use Parallel.ForEach does that imply that I should always be using AsParallel? e.g. Are both of these correct (everything else being equal)? without AsParallel: List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)), f => list.Add(f)); or with AsParallel? List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)).AsParallel(), f => list.Add(f));

    Read the article

  • Item value in JSTL foreach loop not working in Portlet

    - by danimajo
    Given the following Portlet Code: ArrayList nameList = new ArrayList(); nameList.add("Willi Willisch"); nameList.add("Seppi Seppisch"); renderRequest.setAttribute("names", nameList); And the following JSP Code: <c:forEach var="aName" items="${names}"> <tr> <td>${aName} </td> </tr> </c:forEach> Prints out: ${aName} ${aName} I don't have any clue why a $(aName) isn't evaluated. The forEach loops works, because ${aName} is printed out twice ....

    Read the article

  • Code won't exit foreach block

    - by Matt
    I've got the following C# code segment that takes a list, finds objects that are ready to update, then shoves them into a temp list, deletes from the main list, and then goes on its merry way. My issue is that the foreach block, which cycles through my main list, won't exit. TempLog.Clear(); //Ensure TempLog is empty foreach (CLogger ready in PlayerLog) { if (ready.UpdateReady == true) // Record is ready to be updated in database { TempLog.Add(ready); // Add record to templog PlayerLog.Remove(ready); // Remove from playerlog } } <---- Never reaches this point if (TempLog.Count > 0) // Just check that templog isn't empty { new Thread(Update).Start(); // Run update code } I've put heaps of debugging in, and I can watch PlayerLog start at 1, TempLog at 0, then it enters the foreach loop, picks up that the record UpdateReady flag is on, TempLog goes to 1, PlayerLog goes to 0, then it just stops.. No errors, just stops.. Thanks for the help :)

    Read the article

  • C# Lists, Foreach, and Types

    - by user406470
    I was wondering if there is a version of foreach that checks only for a specific type and returns it. For example consider this class tree: org.clixel.ClxBasic - org.clixel.ClxObject - org.clixel.ClxSprite - WindowsGame1.test Then consider this code public List<ClxBasic> objects = new List<ClxBasic>(); foreach(GroupTester tester in objects) { tester.GroupTesterOnlyProperty = true; } tester.GroupTesterOnlyProperty is a property created in GroupTester. Is there some way to make something like this work, like an overload of foreach, or another snippet that might help me? I want to make it easy for a programmer to sort through the lists grabbing only what type they need.

    Read the article

  • Traverse multi dimensional array recusively without using foreach

    - by ejaz
    I have an array like this and the code using foreach loop. $arr = array( array ( array( 'CAR_TIR', 'Tires', 100 ), array( 'CAR_OIL', 'Oil', 10 ), array( 'CAR_SPK', 'Spark Plugs', 4 ) ), array ( array( 'VAN_TIR', 'Tires', 120 ), array( 'VAN_OIL', 'Oil', 12 ), array( 'VAN_SPK', 'Spark Plugs', 5 ) ), array ( array( 'TRK_TIR', 'Tires', 150 ), array( 'TRK_OIL', 'Oil', 15 ), array( 'TRK_SPK', 'Spark Plugs', 6 ) ) ); function recarray($array) { foreach($array as $key=>$value) { if(is_array($value)) { RecArray($value); } else { echo "key = $key value = $value"; } } } recarray($arr); I have to traverse the array using recursion and without using foreach. I would appreciate it if any one can help me

    Read the article

  • Best practice for creating objects used in for/foreach loops

    - by StupidDeveloper
    Hi! What's the best practice for dealing with objects in for or foreach loops? Should we create one object outside the loops and recreate it all over again (using new... ) or create new one for every loop iteration? Example: foreach(var a in collection) { SomeClass sc = new SomeClass(); sc.id = a; sc.Insert(); } or SomeClass sc = null; foreach(var a in collection) { sc = new SomeClass(); sc.id = a; sc.Insert(); } Which is better?

    Read the article

  • Powershell enters foreach loop with null object

    - by SteB
    I'm listing all backups in a given directory: $backups = Get-ChildItem -Path $zipFilepath | Where-Object {($_.lastwritetime -lt (Get-Date).addDays(-7)) -and (-not $_.PSIsContainer) -and ($_.Name -like "backup*")} If I set it to deliberately return no files (.addDays(-600) then the following prints "Empty" (as expected): if (!$backups) { "Empty" } If I try to list the names with an empty $backups variable: foreach ($file in $backups) { $file.FullName; } I get nothing (as expected), if I change this to: "test"+ $file.FullName; then I get a single "test" under the "Empty". How is this possible if $backups is empty?

    Read the article

  • c:forEach.items getting repetitively called

    - by Joshua
    Environment: Seam, Richfaces The following code snippet causes the method getUsers to be called multiple times, how do I avoid this in my application so that it gets called only once. <c:forEach items="#{userHome.getUsers()}" var="_user"> </c:forEach>

    Read the article

  • asp.net mvc user control problem foreach loop

    - by mazhar
    Previous post <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" % <% MvcApplication1.Models.FeaturesRepository _model = new MvcApplication1.Models.FeaturesRepository(); % <% foreach (var md in _model.GetAllFeatures()) { % <%--<% if (md.int_ParentId == 0) { %--% <%= md.vcr_FeaturesName % <%--<% } %--% <% } % It is with reference to the previous post above.Is there something wrong with the foreach loop(The result is correct but it is displaying the series of Add,Add,Add,Add,Add,Add...,which is the last record of the getallfeatures.

    Read the article

  • Converting ObsevableCollection foreach to lambda.

    - by Jitendra Jadav
    Hello Guys, I am working some ObservableCollection converting to lembda it will give me error this is my actual code . foreach (var item in Query) { userDetail.Add(new UserDatail(item.ID,item.Name, item.Address, item.City, item.Pin, item.Phone)); } and I am try to add as lembda Query.ToList().ForEach(x => userDetail.Add(x.ID,x.Name,x.Address,x.City,x.Pin,x.Phone)); This will give me error. Thanks..

    Read the article

  • Rewrite the foreach using lambda + C#3.0

    - by Newbie
    I am tryingv the following foreach (DataRow dr in dt.Rows) { if (dr["TABLE_NAME"].ToString().Contains(sheetName)) { tableName = dr["TABLE_NAME"].ToString(); } } by using lambda like string tableName = ""; DataTableExtensions.AsEnumerable(dt).ToList().ForEach(i => { tableName = i["TABLE_NAME"].ToString().Contains(sheetName); } ); but getting compile time error "cannot implicitly bool to string". So how to achieve the same.? Thanks(C#3.0)

    Read the article

  • Refactoring nested foreach statement

    - by dotnetdev
    Hi, I have a method with a nested foreach collection (iterate a set of objects and then look inside each object). I saw in a book a good pattern to make this much more elegant but cannot remember/find the code example. How else could I make this more tidy? The code is just a typical nested foreach statement so I have not provided a code sample. Thanks

    Read the article

  • Foreach loop problem for Iqueyable object

    - by Vikas
    Hi, Can we use foreach loop for Iqueryable object? I'd like to do something as follow: query = Iqueryable<Myclass> = objDataContext.Myclass; // objDataContext is an object of LINQ datacontext class int[] arr1 = new int[] { 3, 4, 5 }; foreach (int i in arr1) { query = query.Where(q => (q.f_id1 == i || q.f_id2 == i || q.f_id3 == i)); } It gives me wrong output as each time value if i is changed.

    Read the article

  • Unset an array element inside a foreach loop

    - by Summer
    I'm accessing an array by reference inside a foreach loop, but the unset() function doesn't seem to be working: foreach ( $this->result['list'] as &$row ) { if ($this_row_is_boring) { unset($row); } } print_r($this->result['list']); // Includes rows I thought I unset Ideas? Thanks!

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >