w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
For loop inside jQuery call?
You need to build your object first: var headers = {}; for(var i = 0; i<numberOfColumns; i++) { headers[i] = { sorter: 'fancyNumber' }; } $("#" + gridView).tablesorter({ headers: headers, //... }); I'm guessing at the output you want based on your (incorrect) syntax, so you may need to tweak it a little, but the idea is correct.

Categories : Javascript

Angular resource (ngResource) won't make the AJAX call when called inside a function
You are declaring $scope.onFileRead as a function. What is calling onFileRead? When you move the call outside of the function, it is being run as part of initialization. What provides the input file? Probably bind to the onFileRead function from something in your DOM.

Categories : Angularjs

how to call stored procedure inside for loop
your connection is going lost so before calling stored procedure first close the connection and again create connectivity with database <?php $sum=0; for($i=0;$i<10;$i++){ mysql_close(); // close connection // create connectivity $overall_sat=mysql_query("call daily_sales('HO Bangalore','2013-07-01','2013-07-30')"); while($row=mysql_fetch_row($overall_sat)){ echo "<pre>"; print_r($row);?> <td><?php echo $row['0']; $sum=$sum+$row['sat'];?></td> <?} } if(!$overall_sat){ echo mysql_error(); } ?>

Categories : PHP

Speed up function call inside loop
If func() always returns the same value for a given set of inputs (e.g. not time-dependent, sequence dependent etc.), then you could do the following: 1. Whenever you call func(), save the result to a cache [using values of k1...through k8 as the key to the cache-entry] 2. Before calling func(), check if you already have the required value cached The cache itself could be a Map, where you constuct the key by concatenating k1... thru ... k8 in some way that is appropriate to their data-type.

Categories : C++

Function call inside loop taking only last iteration
The code below should work, but as I commented above, please read about closure so you know why. if (ACTIVETICKETS.length > 0) { for (var m in ACTIVETICKETS) { (function(x) { if (ACTIVETICKETS.hasOwnProperty(x)) { var marker = new L.Marker(new L.LatLng(ACTIVETICKETS[x].location.x, ACTIVETICKETS[x].location.y)); createHtmlForPopUp(x, function(data){ console.log(x); marker.bindPopup( data ); // calling a function with callback tile_layer.addLayer(marker); }); } })(m); } // for loop ends here }

Categories : Javascript

jQuery Ajax call inside for loop, not working
Even the ajax requests are sent synchronously but the responses may not come back in the order that are sent. My guess is that you want to simulate a synchronous request and response, then one way to do that is to nest the ajax calls in the success block. $.ajax{( data: 'req:1', success: { $.ajax{( data: 'req:2', success: { data: 'req:3', ... )} )} )}

Categories : C#

How to enumerate through NSArray of NSDictionaries with a block call inside the loop?
I think of your problem as a standard consumer-producer problem. You can create a queue count for the amount of items that will be processed (int totalToProcess=self.usersArray.count). Each time the completion handler is hit, it will do totalToProcess--. When totalToProcess reaches 0 you have processed all of the elements in your queue and can refresh your table. If I understand your question correctly I believe this solves your problem. If not, hopefully I can with a bit more information.

Categories : IOS

How can I perfectly make a loop inside a loop which also inside another loop?
Just addressing the output part, the following code is a way to do what you described: (formatting needs a little work) #include <windows.h> #include <ansi_c.h> enum { name1, name2, name3, name_max }; char *name[name_max]={"name1","name2","name3"}; char *score1[name_max]={"12","11","1"}; char *score2[name_max]={"1","13","22"}; int main(void) { int line; printf("Number Player Name Score "); printf(" Game1 Game 2 "); for (line=name1;line < name_max;line++) { printf("%d %s %s %s ", line+1, name[line], score1[line], score2[line]); } getchar(); return 0; } With the following results:

Categories : C

JavaScript: Optimizing loop inside a loop inside a loop
Change daysOfWeek to an object: var daysOfWeek = { Mon: "Monday", Tue: "Tuesday", ... }; Then you can just access daysOfWeek[property] instead of searching daysOfWeek with a loop.

Categories : Javascript

FOR LOOP in Angular Service NOT Working - While Loop Works
this.convert = function (srctxt) { var a = "", x = 0, ans = ''; for (x = 0; x < srctxt.length; x++) { ans += "X"; } return ans; }; Shorter version var str = 'abcde'; str.replace(/w/gi, 'X');

Categories : Javascript

for loop over Model List in MVC script and access Jquery inside loop
Looks like your selector #contactPhone select don't works cause select control also has contactPhone id. Check with .appendTo('#contactPhone'). BTW, you can use helper to populate dropdown list with your model: @{ new list = Model.worklist.Select(x => new SelectListItem { Text = x.PhoneNumber.ToString(), Value = x.PhoneNumber.ToString() }).ToList(); } @Html.DropDownListFor(model => model.PhoneNumber, list, new { id = "contactPhone" })

Categories : Javascript

Javascript, setInterval starts after while loop? how to make it start inside while loop?
What is happening is you are asking the computer to run the nested inner function once per millisecond. And you are asking this to be done ten times in a row, so by the end, the computer should be sending an alert exactly ten thousand times per second. I'm surprised it doesn't consume all the CPU and consume all memory and cause a fatal error. This will continue until you call clearInterval(), or until the window is closed. http://www.w3schools.com/jsref/met_win_setinterval.asp

Categories : Javascript

Can a termination variable in a condition of for loop be changed inside the loop?(Java)
The string length gets calculated every loop, and your for could throw an IndexOutOfBoundsException if your string becomes too short. IMHO yours is a very bad practice, for loops are intended to make a determined number of loops and should never be stopped, also their stop condition should never be changed inside the loop, you should use a while if you don't know how many iterations you want to do. But this is my personal opinion :)

Categories : Java

I'm considering placing a while loop inside a parent while loop that has the exact same conditions. Can I avoid this with a better object iteration?
You can return false; inside $.each() to break the loop. $(qgAnsArray[]).find('jOption').each(function(){ if($(this).attr('correct') == 'false') { $('#qg_options').append('<li><span class="qg_option">' + $(this).text() + '</span></li>'); return false; } }); If you only want the first instance of an element, you can use first(): var elem = $(qgAnsArray[]).find('jOption[correct="false"]').first();

Categories : Javascript

Make an If statement from stuff inside a foreach loop outside the loop?
As you might already experienced the construct you propose is not desired since the if statement will be executed after the loop has already ended. You can use the continue keyword to jump to the next iteration and skip fields you're not interested in. foreach ($section['fields'] as $k => $type) { if ($type['type'] != 'switch') { continue; } // do stuff } http://php.net/manual/en/control-structures.continue.php

Categories : PHP

a while loop inside a for loop not working in codeigniter view file
Here's how you can do it with just a check of the element index <div class="row"> <?php for($i=0; $i < count($headings); ): ?> <?if($i > 0 && $i%3 == 0):?> </div><!-- end of div.row --> <div class="row"> <?endif?> <div class="span4"> <?php $heading = current($headings); ?> <h2><?= key($headings); ?></h2> <p><?= $heading['description']; ?></p> <p><a class="btn" href="<?= $heading['link']; ?>">View details &raquo;</a></p> <?php next($headings); ?> <?php $i++; ?> </div> <!-- end of div.span4 --> <?php endfor; ?> </div><!-- end of div.

Categories : PHP

while loop inside a trigger to loop through all the columns of table in sql
Try this one - ALTER TRIGGER [dbo].[trgAfterUpdate] ON [dbo].[tbl_User] AFTER UPDATE AS BEGIN SET NOCOUNT ON SET XACT_ABORT ON DECLARE @DocumentUID UNIQUEIDENTIFIER DECLARE cur CURSOR FORWARD_ONLY READ_ONLY LOCAL FOR SELECT DocumentUID, ... FROM INSERTED OPEN cur FETCH NEXT FROM cur INTO @DocumentUID, ... WHILE @@FETCH_STATUS = 0 BEGIN DECLARE @BeforeChange XML , @AfterChange XML SELECT @BeforeChange = ( SELECT * FROM DELETED WHERE [DocumentUID] = @DocumentUID FOR XML RAW, ROOT ) , @AfterChange = ( SELECT * FROM INSERTED WHERE [DocumentUID] = @DocumentUID FOR XML RAW, ROOT

Categories : Sql Server

Strange behaviour in foreach-loop inside for-loop
Your code could be a bit easier to use like this. There is no point in using the next and key operations when you're already in a foreach() loop that provides that data for you. Since the foreach loop already iterates over each element in the array, calling next() manually simply causes PHP to SKIP every other element. foreach($_POST['guest'] as $idx => $guest) { foreach($guest as $key => $val) { echo "$idx: $key => $val<br>"; } } which would echo out 1: name => foo 1: veg => ... etc... 2: name => bar etc...

Categories : PHP

How do I "loop" through JSON array inside foreach loop?
Use a nested loop for the answers. $tab = 0; foreach ($question as $items) { $i++; $j = 0; if ($i > 1) { $hide = ' hide'; } $this_q = "<div class='question-holder" . $hide . "' id='q" . $i . "'> <h2>" . $items->Question . "</h2> <ul class='answers' id='quiz-answers" . $i . "'> "; foreach ($items->Answers as $ans) { $tab++; $j++; $qa = "$i-$j"; $this_q .= "<li> <input tabindex='" . $tab . "' type='radio' name='txtAnswer" . $qa . "' id='txtAlt" . $qa . "' value='sdsds'> <label for='txtAlt" . $qa . "'><span>" . $ans->Answers . "</span></label> </li> ";

Categories : PHP

Nested While loop only runs inside loop correctly
mysqli_fetch_array is similar to array_pop() in that once it fetches a result, it's not going to fetch that result again. So my guess is that your $row_wind loop is actually running through just fine, but the second time through the $row_alert loop looks for more results, finds that it's already run through them (in the loop where $row_wind = 'CT'). If you put some debug info inside the $row_wind loop but outside the $row_alert loop you should see the difference. To fix this, you'll either have to re-run the $result_user_alerts query before the inner loop, or - probably better if the inner query isn't dependent on the state - run mysqli_fetch_all() beforehand to fetch all your results for the inner loop up front, and then loop through the resulting array with your inner loop with a fore

Categories : PHP

How to call local MVC 4 function inside ajax call
The problem is using server side helper function in the separate js file. If you need to have ajax call in the separate js file, set @TokenHeaderValue() value to a hidden field and read the value of hidden field in the js file.

Categories : Asp Net Mvc

No for loop will run inside for loop. Testing for primes
for (int k = 0; k > 10; k++) { System.out.println(k); } k is not greater than 10, so loop will will never execute. I think what want is k<10, isn't it? for (int k = 0; k < 10; k++) { System.out.println(k); }

Categories : Java

Reassign loop variable inside for loop. Bug?
Because $i = 0 is not always executed. It is only executed if the account did not exist. The account is then created, so on the next pass $i is not reset to 0. You need the context around the code as well. A simplified view of just this behavior: for($i = 0; $i < $numAccounts; $i++) { $accountExistsQ = mysql_query("SELECT id FROM networkBlocks WHERE accountAddress = '".$transactions[$i]["txid"]."' ORDER BY blockNumber DESC LIMIT 0,1")or die(mysql_error()); $accountExists = mysql_num_rows($accountExistsQ); if(!$accountExists) { mysql_query("INSERT INTO `networkBlocks` (`blockNumber`, `timestamp`, `accountAddress`, `confirms`, `difficulty`) ". "VALUES ('$assoc_block', '$assoc_timestamp', '" .$transactions[$i]["txid"]. "', '" .$transactions[$i]["confirmations"]

Categories : PHP

for loop wont loop inside a function - C
When you write CheckGuess() you need to do it like this: bool CheckGuess(int guess, int nums[], int numsCount) and then call it with: if (CheckGuess(userGuess, nums, sizeof nums / sizeof *nums) Checkguess isn't "receiving" the size. Inside that function it's just a pointer.

Categories : C

while loop inside for loop is not showing all results but only 1
for ($x = 0; $x < $runs; $x++) { while(++$i<1001)echo$i%15?$i%5?$i%3?$i:'koukou':'roukou':'koukouroukou'," "; } should be for ($x = 0; $x < $runs; $x++) { $i=0; while(++$i<1001)echo$i%15?$i%5?$i%3?$i:'koukou':'roukou':'koukouroukou'," "; }

Categories : PHP

Run a function inside a while loop inside a string?
Since your call is trying to include the result of the function, you'll just need to make sure you're returning all the lines generated along the way. There are many ways to do that, here's one: function ye($coid) { $yest = date("Y-m-d", time() - 86400); $inouty= mysql_query("SELECT clockings.id AS cid,clockings.uid, clockings.con, clockings.coff, staff.sname ,staff.id, staff.act, staff.coid FROM clockings LEFT JOIN staff ON clockings.uid=staff.id WHERE clockings.dte = '$yest' AND staff.coid =$coid ORDER BY staff.id, clockings.id")or die(mysql_error()); $result = ""; while ($row = mysql_fetch_assoc($inouty)) { $sname = htmlspecialchars($row['sname']); $in = htmlspecialchars($row['con']); $out = "- ". htmlspecialchars($row['coff']); $result .= "$s

Categories : PHP

While loop inside for loop in Matlab
With the example you showed, you have to initialize b or the while-statement cannot be evaluated when it is first called. Do it inside the for-loop to avoid false positives after the first for-iteration: n=100; for ii=1:n b = 0; while b<0.5 x(ii)=rand; b=x(ii); end end Or, without b: n=100; x = zeros(1,100); for ii=1:n while x(ii)<0.5 x(ii)=rand; end end

Categories : Matlab

angular js '?' in ng-src causes infinite loop
Well I think the problem is the getRandom function returning a different value every time it's called. Here's what happens: Angular call your function Gets the value See's it's different from the previous value Marks the cycle as dirty After the cycle is finished it re-runs the cycle thus getting a new value ... The idea would be to have getRandom give discreet values over a period of time. For example only give a new value every 1, 10, 30 sec whatever you see fit. This advice applies to many things, actually. Angular provides no guarantees about how many times it will call your functions that are found in bindings. So you need to make them fast and also you need to make sure that for the same input they return the same output(most times, though in this case it might be justified). A

Categories : Angularjs

Call external API by Angular JS
To enable cross site requests angularjs $http docs Most probably you won't get this error when running a deployed instance as you won't be on the localhost. For testing purposes, you can do: myApp.config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; }]);

Categories : Angularjs

How to stop for loop execution untill DWR method execution completion which is inside the for loop
You can use "asynchronous pseudo-recursion" instead of a for loop, with the general pattern that I use being: var pods = [ ... ]; (function loop() { if (pods.length) { var pod = pods.shift(); // take (and remove) first element // do something with "pod" ... // recurse - put this inside a finish callback if "do something" is async loop(); } })(); // closing braces start invocation immediately where in your case, the call to loop should be the last thing inside your callback function. NB: This pattern can also be used to avoid the "browser not responding" error seen with longer running non-async operations by replacing the call to loop() with setTimeout(loop, 0). This use of setTimeout turns a synchronous recursive function into

Categories : Javascript

How to detect when angular is in its digest loop
You can check if a $digest is already in progress by checking $scope.$$phase. if(!$scope.$$phase) { //$digest or $apply } See a more detailed answer here: Answer by Lee

Categories : Angularjs

Call Angular Function with Jquery
You can access the scope of an angular element if you have an ID tag attached to the same DOM element as the ng-controller: the DOM: <div id="mycontroller" ng-controller="mycontroller"></div> your controller: function mycontroller($scope) { $scope.myfunction = function() { //do some stuff here } } in jquery you do this and it will access that controller and call that function : angular.element('#mycontroller').scope().myfunction(); Do remember to call angular.element('#mycontroller').scope().$apply() if you update a function variable within scope in myfunction, it will not work otherwise (thanks @andersh)

Categories : Angularjs

How to Call Pagemethod in Angular js Service
You want to look at factory() and $http pseudo code: angular.factory("PageMethods", ["$http", function($http){ return { GetPracticeLocations : function(){ return $http.get("/someurl"); } } }]);

Categories : Asp Net

How to call an angular resource from a service
Inject the service in your controller like; yourApp.controller('ControllerName',function(MonitoringCRUDControllerService){ $scope.refresh = function() { MonitoringCRUDControllerService.query().then(function(value) { $scope.myData = value; }); }; }); Hope it helps.

Categories : Angularjs

Text inside tag outside of output tag in Angular.js
I think I know the reason for this, the link if html tag (that from head to include stylesheet) that is single self closing tag, and it seams that how parser parse it before Angular is executed.

Categories : Javascript

Infinite loop with Angular expression binding
Even though your async function returns the same exact string every time, the $digest cycle is fired in loops because your function also makes an ajax call with $http service. $http service triggers $rootScope.$apply() when requests are completed and since $apply triggers a $digest cycle it makes your view expression to be re-evaluated, which in return causes your async function to be called again, and so on... app.controller('MainCtrl', function($scope, $http) { $scope.getValue = function(){ return 'some value'; } $scope.getValueAsync = function(){ $http.get('myfile.html') .success(function (data, status, headers, config) { return 'some async value'; }); return 'file not found'; } }); <div>{{getValueAsync()}}</div> Moral of the

Categories : Angularjs

Autocomplete Directive in ng-repeat loop Angular
You need to transclude your directive. Because your directive is nested in a ng-repeat the contents of the directive are not being compiled into the DOM, hence they are not working. Directives have a transclude attribute and coupled with the ng-transclude tag will allow your directives to work when nested in a ng-repeat Some Resources to get you started: This article is a great starter for directives and has a nice introduction to transclusion. Here is another source giving some examples of an transclude and compile in a ng-repeat.

Categories : Jquery

angular: ng-class in ng-repeater , duplicate call
Angular can evaluate an expression multiple times during a digest cycle and hence execution of function happens again and again. As explained in the documentation here Angular enters the $digest loop. The loop is made up of two smaller loops which process $evalAsync queue and the $watch list. The $digest loop keeps iterating until the model stabilizes, which means that the $evalAsync queue is empty and the $watch list does not detect any changes. Since you $watch expression is a function it can get called multiple time. Alternatively look at $routeChangeStart event in $route service. You can subscribe to this event. Create a variable on your scope and do the ng-class binding to that variable

Categories : Javascript

Function within angular directive that I can call from the controller
Firstly in your HTML change myDir to my-dir. In your case you dont need to give an id to your div: <div my-dir>My dir</div> <button ng-click="clickme()">click me</button> Now expose dirFunction to the scope. This would make it possible for your controller to access this function: app.directive("myDir", function(){ return function(scope){ scope.dirFunction = function(){ alert("hello world"); } } }); And from within your controller just call it as $scope.dirFunction(): app.controller("Control", function($scope){ $scope.clickme = function(){ $scope.dirFunction(); } }); NOTE: You should not do DOM manipulation inside your controller: angular.element('#myDir').dirFunction(); in controller is a bad way to co

Categories : Angularjs

How do you call an Angular $scope.Function from href?
Just use ngClick like @Mike says. I don't see the reason to use angular in href . Something like: <a href="" ng-click="ActiveChange('topStories');">Top Stories</a> Or leave it empty: <a href ng-click="ActiveChange('topStories');">Top Stories</a>

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.