Search Results

Search found 834 results on 34 pages for 'looping'.

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

  • PHP - Nested Looping Trouble

    - by Jeremy A
    I have an HTML table that I need to populate with the values grabbed from a select statement. The table cols are populated by an array (0,1,2,3). Each of the results from the query will contain a row 'GATE' with a value of (0-3), but there will not be any predictability to those results. One query could pull 4 rows with 'GATE' values of 0,1,2,3, the next query could pull two rows with values of 1 & 2, or 1 & 3. I need to be able to populate this HTML table with values that correspond. So HTML COL 0 would have the TTL_NET_SALES of the db row which also has the GATE value of 0. <?php $gate = array(0,1,2,3); $gate_n = count($gate); /* Database = my_table.ID my_table.TT_NET_SALES my_table.GATE my_table.LOCKED */ $locked = "SELECT * FROM my_table WHERE locked = true"; $locked_n = count($locked); /* EXAMPLE RETURN Row 1: my_table['ID'] = 1 my_table['TTL_NET_SALES'] = 1000 my_table['GATE'] = 1; Row 2: my_table['ID'] = 2 my_table['TTL_NET_SALES'] = 1500 my_table['GATE'] = 3; */ print "<table border='1'>"; print "<tr><td>0</td><td>1</td><td>2</td><td>3</td>"; print "<tr>"; for ($i=0; $i<$locked_n; $i++) { for ($g=0; $g<$gate_n; $g++) { if (!is_null($locked['TTL_NET_SALES'][$i]) && $locked['GATE'][$i] == $gate[$g]) { print "<td>$".$locked['TTL_NET_SALES'][$i]."</td>"; } else { print "<td>-</td>"; } } } print "</tr>"; print "</table>"; /* What I want to see: <table border='1'> <tr> <td>0</td> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>-</td> <td>1000</td> <td>-</td> <td>1500</td> </tr> </table> */ ?>

    Read the article

  • Stopping looping thread in Java

    - by halfwarp
    I'm using a thread that is continuously reading from a queue. Something like: public void run() { Object obj; while(true) { synchronized(objectsQueue) { if(objectesQueue.isEmpty()) { try { objectesQueue.wait(); } catch (InterruptedException e) { e.printStackTrace(); } obj = objectesQueue.poll(); } } // Do something with the Object obj } } What is the best way to stop this thread? I see two options: 1 - Since Thread.stop() is deprecated, I can implement a stopThisThread() method that uses a n atomic check-condition variable. 2 - Send a Death Event object or something like that to the queue. When the thread fetches a death event it exists. I prefer the 1st way, however, I don't know when to call the stopThisThread() method, as something might be on it's way to the queue and the stop signal can arrive first (not desirable). Any suggestions?

    Read the article

  • Looping through selected values in multiple select combobox JQuery

    - by Roland
    I have the following scenario. I have a combobox where multiple selection is available. <select id="a" multiple="multiple"> <option value="">aaaa</option> <option value="">bbbb</option> <option value="">cccc</option> <option value="">dddd</option> </select> Now I also have a button <button type="button" id="display">Display</button> When a user clicks on this button, it should list all the selected values of the dropdown in an alert box My JS code looks as follows $(document).ready(function() { $('#display').click(function(){ alert($('#a').val()); }); }); Any pointers will be appreciated

    Read the article

  • PHP for loop isn't looping after APC installation

    - by BoRo
    So I installed APC and i all of the sudden my for loops only run once and increment the value then stops. I dont get what's going on, it worked fine before APC was installed. Any Suggestions? EDIT: I managed to narrow it down to the increment. for some reason if I have an array let's say string[], and have the for loop list through the values like with string[$i] It only does it for the first one, I can manually echo/print out the array elements to check if the array is the problem but all elements have the appropriate data/values. EDIT #2: Well the code looks something like (it scrapes a page for images and gets some data from it): $str = explode('<div class="images" align="center">',$str); for($i=1;$i<11;$i++){ $url3 = $str[$i]; $url3 = extstr3($url3,'class="filename">','</div>'); $urlname = extstr3($url3,'<a href="','</a>'); $name = extstr3($urlname,'target="_blank">','.jpg'); $url3 = extstr3($url3,'<a href="','" target="_blank">'); $name = str_replace ('_', ' ', $name); . . .

    Read the article

  • While loop in foreach loop not looping correctly

    - by tominated
    I'm trying to make a very basic php ORM as for a school project. I have got almost everything working, but I'm trying to map results to an array. Here's a snippet of code to hopefully assist my explanation. $results = array(); foreach($this->columns as $column){ $current = array(); while($row = mysql_fetch_array($this->results)){ $current[] = $row[$column]; print_r($current); echo '<br><br>'; } $results[$column] = $current; } print_r($results); return mysql_fetch_array($this->results); This works, but the while loop only works on the first column. The print_r($results); shows the following: Array ( [testID] => Array ( [0] => 1 [1] => 2 ) [testName] => Array ( ) [testData] => Array ( ) ) Can anybody shed some light? Thanks in advance!

    Read the article

  • Android - Looping Activity to Repeat MediaPlayer

    - by Austin Anderson
    I'm trying to create a soundboard for longer audio files and can't figure out how to stop an audio file and start it again without closing the activity. Let's say each audio file is one minute long. If I play the first audio file for 20 seconds and start the next audio file, the first stops playing and the second starts playing. However, if I click the first audio file again, the second stops playing and the first does not. I need help. This is driving me insane. bAudio1 = (ImageButton) findViewById(R.id.bAudio1); bAudio2 = (ImageButton) findViewById(R.id.bAudio2); mpAudio1 = MediaPlayer.create(this, R.raw.audio1); mpAudio2 = MediaPlayer.create(this, R.raw.audio2); bAudio1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(mpAudio1.isPlaying()) { mpAudio1.stop(); } else { if(mpAudio2.isPlaying()) { mpAudio2.stop(); } mpAudio1.start(); } } }); bAudio2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(mpAudio2.isPlaying()) { mpAudio2.stop(); } else { if(mpAudio1.isPlaying()) { mpAudio1.stop(); } mpAudio2.start(); } } }); Thanks.

    Read the article

  • looping through new div as they are created

    - by eknown
    I have a div, let's call it class="phoneNo". Inside the div there are two links, one to add another div just like it, and another to delete the div itself. I'm trying to create a loop where if there's only 1 of these divs, the "delete" link should hide, and if there are more than 1 of these divs, the "delete" link should show up on all the divs. So far I came up with this, but no success: var pCount = $(".phoneNo").length; $(pCount).each(function(){ if (pCount <= 1) { $("a.deleteThis").hide(); } else if (pCount >= 1) { $("a.deleteThis").show(); } return true; });

    Read the article

  • Looping over some selected values in a stored procedure

    - by macca1
    I'm trying to modify a stored procedure hooked into an ORM tool. I want to add a few more rows based on a loop of some distinct values in a column. Here's the current SP: SELECT GRP = STAT_CD, CODE = REASN_CD FROM dbo.STATUS_TABLE WITH (NOLOCK) Order by STAT_CD, SRT_ORDR For each distinct STAT_CD, I'd also like to insert a REASN_CD of "--" here in the SP. However I'd like to do it before the order by so I can give them negative sort orders so they come in at the top of the list. I'm getting tripped up on how to implement this. Does anyone know how to do this for each unique STAT_CD?

    Read the article

  • Looping over ILookup, accessing values

    - by Jono
    I've got a ILookup< string, List<CustomObject> > from some linq I've done. I'd like to now iterate over the results: foreach(IGrouping<string, List<CustomObject>> groupItem in lookupTable) { groupItem.Key; //You can access the key, but not the list of CustomObject } I know I must be misrepresenting a IGrouping as a KeyValuePair, but now I'm not sure how to access it properly.

    Read the article

  • Unable to get set intersection to work

    - by chavanak
    Sorry for the double post, I will update this question if I can't get things to work :) I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 47 65 21 d.complex.10 d.complex.10 46 6 21 46 109 121 192 192 TI am trying to compare the contents of the two file but not in a trivial way. I will explain what I want with an example. If you observe the file content I have typed above, the d.complex.1 of file_1 has "5" similar to d.complex.1 in file_2; the same d.complex.1 in file_1 has nothing similar to d.complex.10 in file_2. What I am trying to do is just to print out those d.complex. which has nothing in similar with the other d.complex. Consider the d.complex. as a heading if you want. But all I am trying is compare the numbers below each d.complex. and if nothing matches, I want that particular d.complex. from both files to be printed. If even one number is present in both d.complex. of both files, I want it to be rejected. My Code: The method I chose to achieve this was to use sets and then do a difference. Code I wrote was: first_complex=open( "file1.txt", "r" ) first_complex_lines=first_complex.readlines() first_complex_lines=map( string.strip, first_complex_lines ) first_complex.close() second_complex=open( "file2.txt", "r" ) second_complex_lines=second_complex.readlines() second_complex_lines=map( string.strip, second_complex_lines ) second_complex.close() list_1=[] list_2=[] res_1=[] for line in first_complex_lines: if line.startswith( "d.complex" ): res_1.append( [] ) res_1[-1].append( line ) res_2=[] for line in second_complex_lines: if line.startswith( "d.complex" ): res_2.append( [] ) res_2[-1].append( line ) h=len( res_1 ) k=len( res_2 ) for i in res_1: for j in res_2: print i[0] print j[0] target_set=set ( i ) target_set_1=set( j ) for s in target_set: if s not in target_set_1: if s[0] != "d": print s The above code is giving an output like this (just an example): d.complex.1.dssp d.complex.1.dssp 1 48 65 d.complex.1.dssp d.complex.10.dssp 46 21 109 What I would like to have is: d.complex.1 d.complex.1 (name from file2) d.complex.1 d.complex.10 (name from file2) I am sorry for confusing you guys, but this is all that is required. I am so new to python so my concept above might be flawed. Also I have never used sets before :(. Can someone give me a hand here?

    Read the article

  • Another php array looping question

    - by Dan
    Been battling with this one for what seems, like forever. I have an array: $url_array It contains this info: Array ( [ppp] => Array ( [0] => stdClass Object ( [id] => 46660 [entity_id] => 0 [redirect_url] => http://www.google.com [type] => Image ) [1] => stdClass Object ( [id] => 52662 [entity_id] => 0 [pixel_redirect_url] => http://www.yahoo.com [type] => Image ) [2] => stdClass Object ( [id] => 53877 [entity_id] => 0 [redirect_url] => http://www.msn.com [pixel_type] => Image ) ) [total_count] => 3 ) I need to loop through it, and do things to each variable. I can get this to work: foreach ($piggies_array as $key => $value) { $id = $value[0]->id; $redirect_url = $value[0]->redirect_url; } Not unsurprisingly, it's only echoing the first value of those variables, but no matter what I try I cannot get it to loop through: $value->redirect_url; $value=>redirect_url; I would appreciate any help.

    Read the article

  • conditional while loop in php?

    - by julio
    I'm pretty sure there's an obvious answer for this-- hoping someone can help me-- I need to do a PHP while loop, but only if a variable is true. And I can't really put the while loop in an "if" statement, which seems like the obvious thing to do, since the code block is huge and it would be ugly and confusing. Do I need to break out the code in the loop into a function, or is there an easier way to deal with this? Here's the basic idea: if(condition){ while(another_condition){ //huge block of code loops many times } } else { // huge block of code runs once } I want the huge block of code to execute regardless of the state of the condition variable-- but only to execute once if condition is false, and execute for as long as another_condition is true if condition is true. Hope that's clear! The following code doesn't work, but gives an idea of what I want to accomplish: if(condition){ while(another_condition){ } // huge block of code if (condition){ } } // closes the while loop-- obviously throws an error though! thanks in advance.

    Read the article

  • Codeigniter view file looping query

    - by user2505513
    Right, I'm unsure about how to code my view file to generate following query results WITHOUT compromising the principles of mvc. Query in model: SELECT * FROM events GROUP BY country, area ORDER BY country, area View: <?php if (isset($query)):?> <?php foreach ($query as $row):?> <h2><?=$row->country?></h2> <h3><?=$row->area?></h3> <?php endforeach;?> <?php endif;?> I want the results to display: England North South West - utilising the GROUP BY parameter As opposed to: England North England South England West Has anybody any advice as to how to achieve this?

    Read the article

  • looping through checkboxes and inserting checkbox values to DB

    - by user1150440
    ASPX Page: <asp:ListView ID="lvSubjects" runat="server" > <LayoutTemplate> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </LayoutTemplate> <ItemTemplate> <asp:CheckBox ID="cbRegularSubjects" Text=<%# Eval("SubjectName") %> runat="server" /> </ItemTemplate> <AlternatingItemTemplate> <asp:CheckBox ID="cbRegularSubjects" Text=<%# Eval("SubjectName") %> runat="server" /> </AlternatingItemTemplate> </asp:ListView> Code Behind: For Each ctrl As Control In Page.Controls If TypeOf ctrl Is CheckBox AndAlso CType(ctrl, CheckBox).Checked Then '**Here I want to get the text of the check box and insert into the DB** End If Next Where am i going wrong??i do not get any error...but this code is not working for me.

    Read the article

  • Why am I getting a TypeError when looping?

    - by Lee Crabtree
    I'm working on a Python extension module, and one of my little test scripts is doing something strange, viz.: x_max, y_max, z_max = m.size for x in xrange(x_max): for y in xrange(y_max): for z in xrange(z_max): #do my stuff What makes no sense is that the loop gets to the end of the first 'z' iteration, then throws a TypeError, stating that "an integer is required". If I put a try...except TypeError around it and check the types of x, y, and z, they all come back as < type 'int' . Am I missing something here?

    Read the article

  • Looping through covariates in regression using R

    - by Kyle Peyton
    I'm trying to run 96 regressions and save the results as 96 different objects. To complicate things, I want the subscript on one of the covariates in the model to also change 96 times. I've almost solved the problem but I've unfortunately hit a wall. The code so far is, for(i in 1:96){ assign(paste("z.out", i,sep=""), lm(rMonExp_EGM~ TE_i+ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+ Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies)) } This works on the object creation side (e.g. I have z.out1 - z.out96) but I can't seem to get the subscript on the covariate to change as well. I have 96 variables called TE_1, TE_2 ... TE_96 in the dataset. As such, the subscript on TE_, the "i" needs to change to correspond to each of the objects I create. That is, z.out1 should hold the results from this model: z.out1 <- lm(rMonExp_EGM~ TE_1 + Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+ Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies) And z.out96 should be: z.out96 <- lm(rMonExp_EGM~ TE_96+ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+ Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies) Hopefully this makes sense. I'm grateful for any tips/advice. cheers, kyle

    Read the article

  • Looping class, for template engine kind of thing

    - by tarnfeld
    Hey, I am updating my class Nesty so it's infinite but I'm having a little trouble.... Here is the class: <?php Class Nesty { // Class Variables private $text; private $data = array(); private $loops = 0; private $maxLoops = 0; public function __construct($text,$data = array(),$maxLoops = 5) { // Set the class vars $this->text = $text; $this->data = $data; $this->maxLoops = $maxLoops; } // Loop funtion private function loopThrough($data) { if( ($this->loops +1) > $this->maxLoops ) { die("ERROR: Too many loops!"); } else { $keys = array_keys($data); for($x = 0; $x < count($keys); $x++) { if(is_array($data[$keys[$x]])) { $this->loopThrough($data[$keys[$x]]); } else { return $data[$keys[$x]]; } } } } // Templater method public function template() { echo $this->loopThrough($this->data); } } ?> Here is the code you would use to create an instance of the class: <?php // The nested array $data = array( "person" => array( "name" => "Tom Arnfeld", "age" => 15 ), "product" => array ( "name" => "Cakes", "price" => array ( "single" => 59, "double" => 99 ) ), "other" => "string" ); // Retreive the template text $file = "TestData.tpl"; $fp = fopen($file,"r"); $text = fread($fp,filesize($file)); // Create the Nesty object require_once('Nesty.php'); $nesty = new Nesty($text,$data); // Save the newly templated text to a variable $message $message = $nesty->template(); // Print out $message on the page echo("<pre>".$message."</pre>"); ?> Any ideas?

    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 thru a list of checkboxes and saving the values, now working properly

    - by Erez
    Hello all, I'm having a bit of a problem with this code. The program gives me a list of checkboxes but a user ID. then u user can change his selection and push the save button (id="btnSaveUserIntersts") and i am trying to save in the hidden textbox all the values of the checkboxes that was choosen. The problem is that i am getting all the time the same selections that came form the database and not getting the new selection that the user made. Can any one tell me what am i doing wrong here? $(document).ready( function() { $('#btnSaveUserIntersts').bind( 'click', function() { var strCheckBoxChecked = new String(); $('input[type=checkbox][checked]').each( function() { strCheckBoxChecked += $(this).val(); strCheckBoxChecked += ','; } ); $('#hidUserInterests').val(strCheckBoxChecked); } ); } ); 10x

    Read the article

  • ResizeEvent Looping?

    - by user309235
    Hello all, I am having an issue with an actionscript event that I am firing every time a flex componenet resizes. In the event, I am altering the height of the component (adding a bit of a buffer), which causes the event to loop in upon itself and continually add height to the component. Is there an elegant way to have this event only fire once?

    Read the article

  • looping array inside list in c#

    - by 3yoon af
    I have a list of array that contains multiple arrays. each array has 2 index .. First, I want to loop the list. Then i want to loop the array inside the list .. How can i do that ? I try to use this way, but it doesn't work ! foreach (string[] s in ArrangList1) { int freq1 = int.Parse(s[1]); foreach (string[] s1 in ArrangList) { int freq2 = int.Parse(s1[1]); if (freq1 < freq2) { backup = s; index1 = ArrangList1.IndexOf(s); index2 = ArrangList.IndexOf(s1); ArrangList[index1] = s1; ArrangList[index2] = s; } backup = null; } } it give me error in line 4.. I try to do the loop using other way .. but i don't know how to continue ! for (int i = 0; i < ArrangList1.Count; i++) { for (int j = 0; j < ArrangList1[i].Length; j++) { ArrangList1[i][1]; } } I use C# language .. Can someone help me, please?

    Read the article

  • Looping the layout that was set up in Interface Builder

    - by Slavenko
    I just need for someone to point me in the right direction of how I should be doing things. I wanted to make an iOS news like app that would have interface resembling Windows Phone. Large and small image tiles that represent one news item each. Now I was thinking to create some basic layout in storyboard, that would consist out of, for example, a title, and a 3 different sized tiles/images (the gray part on the attached image). Now, I would be getting the data as a JSON array that has holds different news categories so I was wondering if somehow the set up layout could be reused in a for loop since the layout will only repeat itself (the red part on the attached image) and oly the data would be different. Can this be done, should I even try doing something like this, or should I try to create an entire layout programmatically? I wouldn't mind doing it programatically, it's just that I don't have much experience in creating layouts that way, and wanted to make sure that I don't do something that I might regret later. Thank you for any help and advice.

    Read the article

  • C# Looping A Process Over And Over Until A User Presses A Key

    - by Soo
    I have a schedule checker that needs to run until a user presses a key to make it stop. My thoughts on doing this are as follows: The user starts the process Process runs every 10 seconds When the process is not running, Console.ReadLine(); gives the user the option to press "q" to stop the process My approach would work fine except the user would have to wait however long the process takes to complete before being able to stop it. Is there any way to simultaneously run the process while being able to take a user input?

    Read the article

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