Search Results

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

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

  • Letting a new PHP page know a new POST value is an Array?

    - by Wintermute
    I have a page that creates an associative array, then passes it as a hidden value to a new PHP page. I have a foreach loop waiting to iterate through it but it coughs up an "invalid argument" error, as if the page doesn't know the value it's working with is an array (Despite "print" showing simply "Array"). This is essentially what I have: //Hidden input to be passed to the next page print "<input type=\"hidden\" name=\"price_list\" value=\"$item_list\"> //Code on the second page for the foreach loop extract($_POST); foreach($price_list as $name=>$price) { ... } But I am simply given "Warning: Invalid argument supplied for foreach() in /home/cut/mg299/public_html/PHP/invoice.php on line 17". The array works fine, as I can iterate on the previous page, and other values are parsed fine to this second page. Do I need to 'reinitialise' this array value?

    Read the article

  • what use does the javascript for each method have (that map can't do)?

    - by JohnMerlino
    Hey all, The only difference I see in map and foreach is that map is returning an array and foreach is not. However, I don't even understand the last line of the foreach method "func.call(scope, this[i], i, this);". For example, isn't "this" and "scope" referring to same object and isn't this[i] and i referring to the current value in the loop? I noticed on another post someone said "Use forEach when you want to do something on the basis of each element of the list. You might be adding things to the page, for example. Essentially, it's great for when you want "side effects". I don't know what is meant by side effects. Array.prototype.map = function(fnc) { var a = new Array(this.length); for (var i = 0; i < this.length; i++) { a[i] = fnc(this[i]); } return a; } Array.prototype.forEach = function(func, scope) { scope = scope || this; for (var i = 0, l = this.length; i < l; i++) func.call(scope, this[i], i, this); } Finally, are there any real uses for these methods in javascript (since we aren't updating a database) other than to manipulate numbers like this: alert([1,2,3,4].map(function(x){ return x + 1})); //this is the only example I ever see of map in javascript. Thanks for any reply.

    Read the article

  • (C#) Get index of current foreach iteration

    - by Graphain
    Hi, Is there some rare language construct I haven't encountered (like the few I've learned recently, some on Stack Overflow) in C# to get a value representing the current iteration of a foreach loop? For instance, I currently do something like this depending on the circumstances: int i=0; foreach (Object o in collection) { ... i++; } Answers: @bryansh: I am setting the class of an element in a view page based on the position in the list. I guess I could add a method that gets the CSSClass for the Objects I am iterating through but that almost feels like a violation of the interface of that class. @Brad Wilson: I really like that - I've often thought about something like that when using the ternary operator but never really given it enough thought. As a bit of food for thought it would be nice if you could do something similar to somehow add (generically to all IEnumerable objects) a handle on the enumerator to increment the value that an extension method returns i.e. inject a method into the IEnumerable interface that returns an iterationindex. Of course this would be blatant hacks and witchcraft... Cool though... @crucible: Awesome I totally forgot to check the LINQ methods. Hmm appears to be a terrible library implementation though. I don't see why people are downvoting you though. You'd expect the method to either use some sort of HashTable of indices or even another SQL call, not an O(N) iteration... (@Jonathan Holland yes you are right, expecting SQL was wrong) @Joseph Daigle: The difficulty is that I assume the foreach casting/retrieval is optimised more than my own code would be. @Jonathan Holland: Ah, cheers for explaining how it works and ha at firing someone for using it.

    Read the article

  • How can i use generic list with foreach?

    - by Phsika
    if i compiled below codes error return foreach loop how can i solve it? Error:Error 1 foreach statement cannot operate on variables of type 'Sortlist.MyCalisan' because 'Sortlist.MyCalisan' does not contain a public definition for 'GetEnumerator' C:\Users\yusuf.karatoprak\Desktop\ExcelToSql\TestExceltoSql\Sortlist\Program.cs 46 13 Sortlist static void EskiMetodlaListele() { MyCalisan myCalisan = new MyCalisan(); Calisan calisan = new Calisan(); calisan.Ad = "ali"; calisan.SoyAd = "abdullah"; calisan.ID = 1; myCalisan.list.Add(calisan); foreach (Calisan item in myCalisan) { Console.WriteLine(item.Ad.ToString()); } } } public class Calisan { public int ID { get; set; } public string Ad { get; set; } public string SoyAd { get; set; } } public class MyCalisan { public List<Calisan> list { get; set; } public MyCalisan() { list = new List(); } }

    Read the article

  • multi-core processing in R on windows XP - via doMC and foreach

    - by Jan
    Hi guys, I'm posting this question to ask for advice on how to optimize the use of multiple processors from R on a Windows XP machine. At the moment I'm creating 4 scripts (each script with e.g. for (i in 1:100) and (i in 101:200), etc) which I run in 4 different R sessions at the same time. This seems to use all the available cpu. I however would like to do this a bit more efficient. One solution could be to use the "doMC" and the "foreach" package but this is not possible in R on a Windows machine. e.g. library("foreach") library("strucchange") library("doMC") # would this be possible on a windows machine? registerDoMC(2) # for a computer with two cores (processors) ## Nile data with one breakpoint: the annual flows drop in 1898 ## because the first Ashwan dam was built data("Nile") plot(Nile) ## F statistics indicate one breakpoint fs.nile <- Fstats(Nile ~ 1) plot(fs.nile) breakpoints(fs.nile) # , hpc = "foreach" --> It would be great to test this. lines(breakpoints(fs.nile)) Any solutions or advice? Thanks, Jan

    Read the article

  • How to print contents from a session variable by looping in a foreach statement

    - by itsover9000
    im trying to write a code where can print and loop through the contents of my session variable by using a foreach statement here is my code <form class="form form-inline" method = "post" action="reportmaker.php"> <select name="rfield"> <option value="">--Select Field--</option> <?php $sc2=mysql_query("SELECT * from searchcolumn s left join report_fields r on s.scol_id=r.field_id where s.category != 'wh'"); foreach($sc2 as $sc){ ?> <option value="<?php echo $sc[advsearch_col]; ?>"><?php echo $sc[advsearch_name]; ?></option> <?php } ?> </select> <button type="submit" value = "submit" id="add" name="add" class="btn pull-right">Add More</button> </form> <?php if(isset($_POST['add'])) { $_SESSION['temp'][]=$_POST['rfield']; } if($_SESSION[temp][]!=""){ foreach($_SESSION[temp][] as $temp) { echo $temp; } } ?> the error that appears with this code is Fatal error: Cannot use [] for reading the line where the error is is this if($_SESSION[temp][]!=""){ i need to print the contents of the session array and this is the only way i know how is there a way to fix this? thanks =========EDIT thanks for the answers guys i finally got it

    Read the article

  • Looping through a method without for/foreach/while

    - by RichK
    Is there a way of calling a method/lines of code multiple times not using a for/foreach/while loop? For example, if I were to use to for loop: int numberOfIterations = 6; for(int i = 0; i < numberOfIterations; i++) { DoSomething(); SomeProperty = true; } The lines of code I'm calling don't use 'i' and in my opinion the whole loop declaration hides what I'm trying to do. This is the same for a foreach. I was wondering if there's a looping statement I can use that looks something like: do(6) { DoSomething(); SomeProperty = true; } It's really clear that I just want to execute that code 6 times and there's no noise involving index instantiating and adding 1 to some arbitrary variable. As a learning exercise I have written a static class and method: Do.Multiple(int iterations, Action action) Which works but scores very highly on the pretentious scale and I'm sure my peers wouldn't approve. I'm probably just being picky and a for loop is certainly the most recognisable, but as a learning point I was just wondering if there (cleaner) alternatives. Thanks. (I've had a look at this thread, but it's not quite the same) http://stackoverflow.com/questions/2248985/using-ienumerable-without-foreach-loop

    Read the article

  • Fetch multiple rows from SQL in PHP foreach item in array

    - by TrySpace
    I try to request an array of IDs, to return each row with that ID, and push each into an Array $finalArray But only the first result from the Query will output, and at the second foreach, it skips the while loop. I have this working in another script, so I don't understand where it's going wrong. The $arrayItems is an array containing: "home, info" $finalArray = array(); foreach ($arrayItems as $UID_get) { $Query = "SELECT * FROM items WHERE (uid = '" . cleanQuery($UID_get) . "' ) ORDER BY uid"; if($Result = $mysqli->query($Query)) { print_r($UID_get); echo "<BR><-><BR>"; while ($Row = $Result->fetch_assoc()) { array_push($finalArray , $Row); print_r($finalArray ); echo "<BR><><BR>"; } } else { echo '{ "returned" : "FAIL" }'; //. mysqli_connect_errno() . ' ' . mysqli_connect_error() . "<BR>"; } } (the cleanQuery is to escape and stripslashes) What I'm trying to get is an array of multiple rows (after i json_encoded it, like: {"finalArray" : { "home": {"id":"1","created":"0000-00-00 00:00:00","css":"{ \"background-color\" : \"red\" }"} }, { "info": {"id":"2","created":"0000-00-00 00:00:00","css":"{ \"background-color\" : \"blue\" }"} } } But that's after I get both, or more results from the db. the print_r($UID_get); does print info, but then nothing.. So, why am I not getting the second row from info? I am essentially re-querying foreach $arrayItem right?

    Read the article

  • Javascript For-Each Loop Syntax Help

    - by radrew
    Hey guys, I've got a complex block of PHP/Javascript that isn't functioning. I'm trying to manipulate a form that contains 4 dropdown select lists. Each dropdown is dependent upon what was selected in the one above it. I apologize for the huge amount of code, but I was hoping someone might be able to spot a syntax error or something else simple that I'm missing. The form in question is located in the right sidebar of the following site: http://www.buyautocovers.com $Manufacturer_array[] = array('id' => 'all', 'text' => $this->__('Choose Make')); $Model_array[] = array('id' = 'all', 'text' = $this-('Choose Model')); $Number_array[] = array('id' = 'all', 'text' = $this-('Choose Year')); $Body_array[] = array('id' = 'all', 'text' = $this-__('Choose Body Type')); $javascript = ' // var a = new Array(); var b = new Array(); var c = new Array(); var d = new Array();'; $M_a = array(); foreach ($rows as $r) { if (!isset($M_a [$r['manufacturer']])) $Manufacturer_array[] = array('id' = $r['manufacturer'], 'text' = $r['manufacturer']); $M_a [$r['manufacturer']][$r['model']][$r['number']][$r['body']] = 1; } $i = 0; foreach ($M_a as $k =$v){ $javascript .= 'a['.$i.']="'.$k.'";b['.$i.'];c['.$i.'];=new Array('; $ii = 0; $s = ''; foreach ($M_a[$k] as $kk =$vv){ $javascript .= ($ii != 0 ? ',' : '').'"'.$kk.'"'; $ss = ''; $iii = 0; foreach ($M_a[$k][$kk] as $kkk = $vvv){ $javascript .= ($iii != 0 ? ',' : '').'"'.$kkk.'"'; $sss = ''; $iiii = 0; foreach ($M_a[$k][$kk][$kkk] as $kkkk = $vvvv){ $sss .= ($iiii != 0 ? ',' : '').'"'.$kkkk.'"'; $iiii++; } $ss .= 'd['.$i.']['.$ii.']['.$iii.']=new Array('.$sss.');'; $iii++; } $s .= 'd['.$i.']['.$ii.']=new Array('.$ss.');'; $ii++; } $javascript .= ');d['.$i.']=new Array();'.$s; $i++; } $javascript .= ' function pop_model(){ var o ="' . $this-('Choose Model') . '"; var sv = $(\'mmn_manufacturer\').value; if(sv != "all"){ var v = a.length; while(v--) if(sv == a[v]) break; for(var i = 0; i < b[v].length; i++) o+=""+b[v][i]+""; } o+=""; $(\'model_select\').innerHTML= o; $(\'number_select\').innerHTML= "' . $this-('Choose Year') . '"; } function pop_number(){ var o ="' . $this-('Choose Year') . '"; var sv = $(\'mmn_manufacturer\').value; if(sv != "all"){ var v = a.length; while(v--) if(sv == a[v]) break; var sv2 = $(\'mmn_model\').value; if(sv2 != "all"){ var v2 = b[v].length; while(v2--) if(sv2 == b[v][v2]) break; for(var i = 0; i < c[v][v2].length; i++) o+=""+c[v][v2][i]+""; } } o+=""; $(\'number_select\').innerHTML= o; $(\'body_select\').innerHTML= "' . $this-('Choose Body Type') . '"; } function pop_body(){ var o ="' . $this-__('Choose Body Type') . '"; var sv = $(\'mmn_manufacturer\').value; if(sv != "all"){ var v = a.length; while(v--) if(sv == a[v]) break; var sv2 = $(\'mmn_model\').value; if(sv2 != "all"){ var v2 = b[v].length; while(v2--) if(sv2 == b[v][v2]) break; var sv3 = $(\'mmn_number\').value; if(sv3 != "all"){ var v3 = c[v].length; while(v3--) if(sv3 == b[v]c[v2][v3]) break; for(var i = 0; i < d[v]c[v2][v3].length; i++) o+=""+d[v]c[v2][v3][i]+""; } } } o+=""; $(\'number_select\').innerHTML= o; } //]] '; $expire = time()+60*60*24*90; if (isset($_GET['Manufacturer'])){ setcookie("Manufacturer_selected", $_GET['Manufacturer'], $expire,'/'); if ($_GET['Manufacturer'] != 'all') $Manufacturer_selected_var = $_GET['Manufacturer']; } elseif (isset($_COOKIE['Manufacturer_selected']) && $_COOKIE['Manufacturer_selected'] != 'all') $Manufacturer_selected_var = $_COOKIE['Manufacturer_selected']; if (isset($_GET['Model'])){ setcookie("Model_selected", $_GET['Model'], $expire,'/'); if ($_GET['Model'] != 'all') $Model_selected_var = $_GET['Model']; } elseif (isset($_COOKIE['Model_selected']) && $_COOKIE['Model_selected'] != 'all') $Model_selected_var = $_COOKIE['Model_selected']; if (isset($_GET['Number'])){ setcookie("Number_selected", $_GET['Number'], $expire,'/'); if ($_GET['Number'] != 'all') $Number_selected_var = $_GET['Number']; } elseif (isset($_COOKIE['Number_selected']) && $_COOKIE['Number_selected'] != 'all') $Number_selected_var = $_COOKIE['Number_selected']; if (isset($_GET['Body'])){ setcookie("Body_selected", $_GET['Body'], $expire,'/'); if ($_GET['Body'] != 'all') $Body_selected_var = $_GET['Body']; } elseif (isset($_COOKIE['Body_selected']) && $_COOKIE['Body_selected'] != 'all') $Body_selected_var = $_COOKIE['Body_selected']; if (isset($Manufacturer_selected_var) && isset($M_a[$Manufacturer_selected_var])) foreach ($M_a[$Manufacturer_selected_var] as $k => $v) $Model_array[] = array('id' = $k, 'text' = $k); if (isset($Manufacturer_selected_var) && isset($Model_selected_var) && isset($M_a[$Manufacturer_selected_var][$Model_selected_var])) foreach ($M_a[$Manufacturer_selected_var][$Model_selected_var] as $k = $v) $Number_array[] = array('id' = $k, 'text' = $k); if (isset($Manufacturer_selected_var) && isset($Model_selected_var) && isset($Number_selected_var) && isset($M_a[$Manufacturer_selected_var][$Model_selected_var][$Number_selected_var])) foreach ($M_a[$Manufacturer_selected_var][$Model_selected_var][$Number_selected_var] as $k = $v) $Body_array[] = array('id' = $k, 'text' = $k); echo $javascript;

    Read the article

  • Mock Assertions on objects inside Parallel ForEach's???

    - by jacko
    Any idea how we can assert a mock object was called when it is being accessed inside Parallel.ForEach via a closure? I assume that because each invocation is on a different thread that Rhino Mocks loses track of the object? Pseudocode: var someStub = MockRepository.GenerateStub() Parallel.Foreach(collectionOfInts, anInt => someStub.DoSomething(anInt)) someStub.AssertWasCalled(s => s.DoSomething, Repeat.Five.Times) This test will return an expectation violation, expecting the stub to be called 5 times but being actually called 0 times. Any ideas how we can tell the lambdas to keep track of the thread-local stub object?

    Read the article

  • Simple stupid foreach loop question

    - by user281180
    In the code below i`m trying to read a list of selected projects and a list of all projects available. I want to store the all the projects that have not been selected from the list of all projects. But with the code below, I`m having list of all projects...Where and how to break the second loop incase projectId.Value == selectedProjectId.Value ? public IEnumerable NotselectedProjects; public IEnumerable NotSelectedProjects() { if (this.NotselectedProjects == null) { List<SelectListItem> result = new List<SelectListItem>(); foreach (var selectedProjectId in selectedProjects) { foreach (var projectId in projectLists) { if (projectId.Value != selectedProjectId.Value) { result.Add(new SelectListItem { Selected = false, Text = projectId.Text, Value = projectId.Value }); this.NotselectedProjects = result.AsEnumerable(); } } } } return this.NotselectedProjects; }

    Read the article

  • Problem with foreach loop and $_GET

    - by phpExe
    I have a very simple foreach loop foreach($tv as $id => $channel) { $ID = $_GET['ID']; if($ID == $id){$class = "currentt";} echo '<a href="http://www.mysite.com/tst.php?ID='.$id.'" class="'.$class.'">'.$channel.'</a><br>'; } With url query, with every click the current class repeated. How can avoid this? Thanks alot.

    Read the article

  • Duplicate Blob field with foreach

    - by JGSilva
    I have some fields (blob) where I have uploaded some images. The images display correctly and I can open it without problem in Photoshop for example. I created a button where user can duplicate the product and everything works fine, but when it comes to duplicate the image entry I got some errors, like 1064 and others ones that I can't remember cause I am working 3 days inside this. Because de original product have 3 or more images I select then and gave an foreach. What I notice when a print de blob is that in the end it eats the next array, like if don't have an end. In other words, the next item got inside that utf-8 character in the print. That gave me some clue. The next approach was to save it in somewhere, and reupload it. The problem is that only the first one works. When I download the image saved, it opens normally so, it is not a saving in disk problem. When I gave a print in the $result, the same happens, is like the image is hungry and ate the next one. Here is the code. Notice = I created the [$count] to see if was not an rewrite in array error. Even tried to , in beging of the foreach, kind of clean the vars… $count=0; foreach ($original_image as $key => $val) { $count++; //$arquivo = ''; //$image = ''; //$file = ''; //$this->image = ''; //$return = ''; $arquivo[$count] = $val['pi_id'].'.'.$val['pi_type']; $image[$count] = $caminho_url.$arquivo[$count]; if (file_exists($image[$count])) { $this->image = Image::factory($image[$count]); $this->image->save($image[$count]); $file[$count]=mysql_real_escape_string(addslashes(fread(fopen($image[$count], "r"), filesize($image[$count])))); $return[$count] = Product::add_image($id_prod, $file[$count], $val['pi_type'],$val['pi_main']); }else { die('no'); } }

    Read the article

  • How to bind to foreach context ?

    - by Rebol Tutorial
    Currently I have this snippet of code: save-blocks: func[file /local f out][ foreach [field1 field2 field3 field4 field5 field6 field7 field8 field9] blocks [ out: copy "" repeat n 9 [ part: get bind to-word rejoin ["field" n] 'field1 out: rejoin [out part ";"] ] remove back tail out write/lines/append f out ] It's not generic enough, I'd like to pass this block: [field1 field2 field3 field4 field5 field6 field7 field8 field9] as parameter and write something like this: save-blocks: func[block file /local f out][ foreach block blocks [ out: copy "" repeat n 9 [ part: get bind to-word rejoin ["field" n] 'field1 out: rejoin [out part ";"] ] remove back tail out write/lines/append f out ] But I don't know how to bind in this case too hard for me :(

    Read the article

  • How can use foreach to Loop Through PHP Array

    - by jtom
    How can use foreach loop to loop through the $Result? $Query = mysql_query("SELECT * FROM mytable"); $Result = array( ); while ($Row = mysql_fetch_array ( $Query) ) { $Result [ ] = $Row; } mysql_free_result($Query); print_r ($Result); ? I just have very vague idea: foreach ($Result ) { echo $row[fname] . ' ' . $row[lname] . ' ' $row[email]; } ? Could someone help please?

    Read the article

  • Write a foreach loop for array of SimpleXMLElements

    - by mjames
    Hi, I am using the XPath in PHP 5 to parse a XML document. The problem I have is writing a foreach to correctly display the following array: XML document sample value 1 value 2 $xmlfile = 'link_to_file.xml'; $xmlRaw = file_get_contents($xmlfile); $xml = new SimpleXMLElement($xmlRaw); $install_files = $xml->xpath('//files'); foreach($install_files as $row) { echo $row['file']; } //var_dump for $row gives the following array(1) { [0]=> object(SimpleXMLElement)#21 (2) { ["file"]=> string(12) "value 1" ["folder"]=> string(8) "value 2" } } Ideally I would like to get the value by using $row['file'] or $row['folder']. Thanks for any help.

    Read the article

  • parallel.foreach with custom collection

    - by SchwartzE
    I am extending the System.Net.Mail.MailAddress class to include an ID field, so I created a new custom MailAddress class that inherited from the existing class and a new custom MailAddressCollection class. I then overrode the existing System.Net.Mail.MailMessage.To to use my new collection. I would like to process the recipients in parallel, but I can't get the syntax right. This is the syntax I am using. Parallel.ForEach(EmailMessage.To, (MailAddress address) => { emailService.InsertRecipient(emailId, address.DisplayName, address.Address, " "); }); I get the following errors: The best overloaded method match for 'System.Threading.Tasks.Parallel.ForEach(System.Collections.Generic.IEnumerable, System.Action)' has some invalid arguments Argument 1: cannot convert from 'EmailService.MailAddressCollection' to 'System.Collections.Generic.IEnumerable' What syntax do I need to use custom collections?

    Read the article

  • Change xml attribute in foreach statement c#

    - by user1913479
    I need to save XML-attribute value in a database, using information if checkbox is checked. If checkbox is checked, the attribute value is "TRUE", otherwise it's false. When I use foreach statement, the last enumerated value is usually assigned. Here is the part of my code: XmlAttribute xmlAttribute = xmlDoc.CreateAttribute("BooleanValue"); foreach (string value in list) //list is a List<object> { XmlNode xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "VALUE", ""); if (checkBox1.Checked || checkBox2.Checked || checkBox3.Checked) xmlAttribute.Value = "TRUE"; if (!checkBox1.Checked || !checkBox2.Checked || !checkBox3.Checked) xmlAttribute.Value = "FALSE"; xmlNode.Attributes.Append(xmlAttribute); xmlNode.InnerText = val; childNode.AppendChild(xmlNode); } When I run my application, I get an XML attribute xmlAttribute "FALSE" value anyway. What I need to have: I need to have the following XML: <ROOT><NODE><VALUE ATTRIBUTE="TRUE">Value 1</VALUE></NODE> <NODE><VALUE ATTRIBUTE="TRUE">Value 2</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 3</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 4</VALUE></NODE> <NODE><VALUE ATTRIBUTE="TRUE">Value 5</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 6</VALUE></NODE> </ROOT> What I actually get: <ROOT><NODE><VALUE ATTRIBUTE="FALSE">Value 1</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 2</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 3</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 4</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 5</VALUE></NODE> <NODE><VALUE ATTRIBUTE="FALSE">Value 6</VALUE></NODE> </ROOT> Because in C# FALSE value is stayed at last position in foreach loop The question is: how do I do to assign the correct values of my attribute. Thanks

    Read the article

  • How to foreach through a 2 dimensional array?

    - by Scott Langham
    If I've got a 2 dimensional array. string[,] table = { { "aa", "aaa" }, { "bb", "bbb" } }; And I'd like to foreach through it like this. foreach (string[] row in table) { Console.WriteLine(row[0] + " " + row[1]); } But, I get the error "Can't convert type string to string[] Is there a way I can achieve what I want, i.e. iterate through the first dimension of the array with the iterator variable returning me the 1 dimensional array for that row? Thanks.

    Read the article

  • List.ForEach method and collection interfaces

    - by tyndall
    In .NET 3.5 List< gains a ForEach method. I notice this does not exist on IList< or IEnumerable< what was the thinking here? Is there another way to do this? Nice and simple short way to do this? I ask because I was at a talk where the speaker said always use the more general interfaces. But why would I use IList< as a return type if I want to be able to turn around and use ForEach? Then I would just end up casting it back to a List<.

    Read the article

  • foreach invalid argument supplied and mysql fetch array issue

    - by La Myse
    i have this code which i use to print some fields from the database. My problem is that i get this error about foreach invalid argument supplied and a mysql fetch array problem. The code is this: foreach( $checked1 as $key => $value){ echo "<th> $value </th>"; } echo "</tr></thead>"; while($row = mysql_fetch_array($result)){ Where $checked1 is an array $checked1 = $_POST['checkbox']; What's the problem here? Thanks..

    Read the article

  • Remove values from array on foreach PHP

    - by user104531
    I have an array like this: Array ( [0] => Array ( [id] => 68 [type] => onetype [type_id] => 131 [name] => name1 ) [1] => Array ( [id] => 32 [type] => anothertype [type_id] => 101 [name] => name2 ) ) I need to remove some arrays from it if the users has permissions or not to see that kind of type. I am thinking on doing it with a for each, and do the needed ifs inside it to remove or let it as it. My question is: What's the most efficent way to do this? The array will have no more than 100 records. But several users will request it and do the filtering over and over.

    Read the article

  • posting multiple radio button values to mysql using "foreach"

    - by jeansymolanza
    i have adjusted my code slightly but i am still having difficulty posting it to the table. could someone please provide me with an example of the foreach array? form page <div style="padding: 15px;"> <span class="loginfail" style="font-size:24px; font-weight: bold">Notifications</span><p> <?php include("progress_insertcomment.php"); ?> <?php // Make a MySQL Connection mysql_select_db("speedycm_data") or die(mysql_error()); $query_comment = "select * from tbl_alert order by id desc limit 1"; $comment = mysql_query($query_comment, $speedycms) or die(mysql_error()); $row_comment = mysql_fetch_assoc($comment); $totalRows_comment = mysql_num_rows($comment); ?> <!--- add notification ---> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <span id="sprytextarea1"> <textarea id='comment' name="comment" style="height: 75px; width:330px;"><?php echo $row_comment['comment']; ?></textarea> </span> <p> <button type="submit">Add</button> <input type="hidden" name="notc" value="1"/> </form> <!--- notification history ---> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table border="0" cellspacing="2" cellpadding="2"> <?php if ( $row_comment == 0 ) { echo "<span style='font-size: 11px;'>No current alerts.</span>"; } else { // Get all the data from the "example" table $result = mysql_query("SELECT * FROM tbl_alert ORDER BY id DESC") or die(mysql_error()); while($rows=mysql_fetch_array($result)){ ?> <tr> <td> <?php echo "<div class='bubble'><div class='pimped'> <blockquote>" . $rows['comment'] . " </blockquote></div> <cite><strong>" . $rows['user'] . "</strong> @ " . $rows['date'] . "</cite> <span style='font-size: 10px;'> <p> <a href='editalert.php?id=". $rows['id'] ."' class='form' >Edit</a>&nbsp;&#8226;&nbsp;<a href='deletealert.php?id=". $rows['id'] ."' class='form'>Delete</a> </span> </div> "; ?> </td> <td valign="top" align="center"><div style="padding-left: 30px;"><span style="font-size: 10px;">Completed?</span> <p class="field switch"> <!--- determine status of notification ---> <?php $status = $rows['status']; ?> <input type="radio" name="selstatus" value="no" <?php if($status == 'yes') {echo 'checked';} else {echo '';} ?>/> <input type="radio" name="selstatus" value="yes" <?php if($status == 'yes') {echo 'checked';} else {echo '';} ?>/> <input type="hidden" name="statusid" value="<?php echo $rows['id']; ?>"/> <label for="radio1" class="cb-enable <?php if($status == 'yes') {echo 'selected';} else {echo '';} ?>"><span>Yes</span></label> <label for="radio2" class="cb-disable <?php if($status == 'no') {echo 'selected';} else {echo '';} ?>"><span>No</span></label> </p> </div></td> </tr> <tr> <td></td> <?php } } ?> <td align="center"><div style="padding-left: 30px;"> <button type="submit">Update</button> <input type="hidden" name="notc2" value="1"/> </div></td> </tr> </table> </form> </div> </body> processing <?php // 6) update notifications if (array_key_exists('notc2',$_POST)) { echo "<p style='font-size: 12px;'>Thank you. The notifications have been updated successfully.<p>"; echo "<p><span style='font-size: 12px;'> <a onClick=\"history.go(-1)\" class='form'>Return</a></p> <p></span> "; exit; }; ?> after doing some research i learnt that the only way to insert multiple radio values into the MYSQL table is to use arrays. there was a similar question raised somewhere on this site: http://stackoverflow.com/questions/1656260/php-multiple-radio-buttons that recommended using a foreach loop. use a foreach loop <?php foreach ( $_POST as $key => $val ) echo "$key -> $val\n"; ?> $key will be the name of the selected option and $val, well, the value. how would this apply to my situation as i am struggling to find any help on the internet. i understand that i would use this on the processing page to pull out any radio values from the previous page and then loop the INSERT MYSQL code within the process until it was all done. any advice would be appreciated! GOD BLESS.

    Read the article

  • insert multiple rows into database from arrays

    - by Mark
    Hi, i need some help with inserting multiple rows from different arrays into my database. I am making the database for a seating plan, for each seating block there is 5 rows (A-E) with each row having 15 seats. my DB rows are seat_id, seat_block, seat_row, seat_number, therefore i need to add 15 seat_numbers for each seat_row and 5 seat_rows for each seat_block. I mocked it up with some foreach loops but need some help turning it into an (hopefully single) SQL statement. $blocks = array("A","B","C","D"); $seat_rows = array("A","B","C","D","E"); $seat_nums = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"); foreach($blocks as $block){ echo "<br><br>"; echo "Block: " . $block . " - "; foreach($seat_rows as $rows){ echo "Row: " . $rows . ", "; foreach($seat_nums as $seats){ echo "seat:" . $seats . " "; } } } Maybe there's a better way of doing it instead of using arrays? i just want to avoid writing an SQL statement that is over 100 lines long ;) (im using codeigniter too if anyone knows of a CI specific way of doing it but im not too bothered about that)

    Read the article

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