Search Results

Search found 41 results on 2 pages for 'forloop'.

Page 1/2 | 1 2  | Next Page >

  • forloop and table in latex

    - by Tim
    Hi, Here is the latex code for my table: \begin{table}{| c || c | c | c || c | c | c | } \caption{Examples of the concepts. \label{tab:conceptsimgs}}\\ \hline \backslashbox{Concept}{Class} &\multicolumn{3}{|c||}{Negative Class} & \multicolumn{3}{|c|}{Positive Class} \\ \hline \forloop{themenumber}{1}{\value{themenumber} < 4}{ %\hline \arabic{themenumber} \forloop{classnumber}{0}{\value{classnumber} < 2}{ \forloop{imagenumber}{1}{\value{imagenumber} < 4}{ & 0 } } \\ \hline } \end{table} Something is wrong in the result however. There is some extra thing at the end of the table, as shown in this image. How can I fix it? Thanks and regards!

    Read the article

  • how to number t-rows ,when table generated using nested forloop in django templates

    - by stackover
    Hi, This part is from views.py results=[(A,[stuObj1,stuObj2,stuObj3]),(B,[stuObj4,stuObj5,stuObj6]),(C,[stuObj7,stuObj8])] for tup in results: total = tot+len(tup[1]) render_to_response(url,{'results':res , 'total':str(tot),}) this is template code: <th class="name">Name</th> <th class="id">Student ID</th> <th class="grade">Grade</th> {% for tup in results %} {% for student in tup|last %} {% with forloop.parentloop.counter as parentid%} {% with forloop.counter as centerid%} <tbody class="results-body"> <tr> <td>{{student.fname|lower|capfirst}} {{student.lname|lower|capfirst}}</td> <td>{{student.id}}</td> <td>{{tup|first}}</td> </tr> {% endfor %} {% endfor %} Now the problems am having are 1. numbering the rows. Here my problem is am not sure if i can do things like total=total-1 in the templates to get the numbered rows like <td>{{total}}</td> 2.applying css to tr:ever or odd. Whats happening in this case is everytime the loop is running the odd/even ordering is lost. these seems related problems. Any ideas would be great :)

    Read the article

  • Simple forloop - Python

    - by RadiantHex
    Hi folks, this is probably too simple of a question, but here I go. I have paginated items, each page contains 100 items. The program fetches items till it reaches the item index specified within item_num This is what I have: item_num = 56 range(0, item_num/100 + (item_num%100 > 0)): get_next_100() I'm not really sure about the (item_num%100 0) boolean I used. Is there anything wrong with what I did?

    Read the article

  • Why isn't this simple PHP Forloop working?

    - by Jake
    First here's the code: <?php $qty = $_GET['qty']; for($i=0; $i < $qty; $i++) { setcookie('animals', $_COOKIE['animals'].'(lion)', time()+3600); } ?> Here's what I'm trying to do: I want to set the value of the "animals" cookie to "(lion)". The number of instances of "(lion)" that should be in the cookie is determined by the "qty" GET parameter's value. So for example if the pages url is: http://site.com/script.php?qty=10 then the value of the cookie should be: (lion)(lion)(lion)(lion)(lion)(lion)(lion)(lion)(lion)(lion) but now it just sets the value once despite the setcookie function being inside the loop, why isn't it working?

    Read the article

  • How to solve this simple PHP forloop issue?

    - by Londonbroil Wellington
    Here is the content of my flat file database: Jacob | Little | 22 | Male | Web Developer * Adam | Johnson | 45 | Male | President * Here is my php code: <?php $fopen = fopen('db.txt', 'r'); if (!$fopen) { echo 'File not found'; } $fread = fread($fopen, filesize('db.txt')); $records = explode('|', $fread); ?> <table border="1" width="100%"> <tr> <thead> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Sex</th> <th>Occupation</th> </thead> </tr> <?php $rows = explode('*', $fread); for($i = 0; $i < count($rows) - 1; $i++) { echo '<tr>'; echo '<td>'.$records[0].'</td>'; echo '<td>'.$records[1].'</td>'; echo '<td>'.$records[2].'</td>'; echo '<td>'.$records[3].'</td>'; echo '<td>'.$records[4].'</td>'; echo '</tr>'; } fclose($fopen); ?> </table> Problem is I am getting the output of the first record repeated twice instead of 2 records one for Jacob and one for Adam. How to fix this?

    Read the article

  • iteration in latex

    - by Tim
    Hi, I would like to use some iteration control flow to simplify the following latex code \begin{sidewaystable} \caption{A glance of images} \centering \begin{tabular}{| c ||c| c| c |c| c|| c |c| c|c|c| } \hline \backslashbox{Theme}{Class} &\multicolumn{5}{|c|}{Class 0} & \multicolumn{5}{|c|}{Class 1} \\ \hline \hline 1 & \includegraphics[scale=2]{../../results/1/0_1.eps} &\includegraphics[scale=2]{../../results/1/0_2.eps} &\includegraphics[scale=2]{../../results/1/0_3.eps} &\includegraphics[scale=2]{../../results/1/0_4.eps} &\includegraphics[scale=2]{../../results/1/0_5.eps} &\includegraphics[scale=2]{../../results/1/1_1.eps} &\includegraphics[scale=2]{../../results/1/1_2.eps} &\includegraphics[scale=2]{../../results/1/1_3.eps} &\includegraphics[scale=2]{../../results/1/1_4.eps} &\includegraphics[scale=2]{../../results/1/1_5.eps} \\ \hline \hline 2 & \includegraphics[scale=2]{../../results/2/0_1.eps} &\includegraphics[scale=2]{../../results/2/0_2.eps} &\includegraphics[scale=2]{../../results/2/0_3.eps} &\includegraphics[scale=2]{../../results/2/0_4.eps} &\includegraphics[scale=2]{../../results/2/0_5.eps} &\includegraphics[scale=2]{../../results/2/1_1.eps} &\includegraphics[scale=2]{../../results/2/1_2.eps} &\includegraphics[scale=2]{../../results/2/1_3.eps} &\includegraphics[scale=2]{../../results/2/1_4.eps} &\includegraphics[scale=2]{../../results/2/1_5.eps} \\ \hline ... % similarly for 3, 4, ..., 22 \hline 23 & \includegraphics[scale=2]{../../results/23/0_1.eps} &\includegraphics[scale=2]{../../results/23/0_2.eps} &\includegraphics[scale=2]{../../results/23/0_3.eps} &\includegraphics[scale=2]{../../results/23/0_4.eps} &\includegraphics[scale=2]{../../results/23/0_5.eps} &\includegraphics[scale=2]{../../results/23/1_1.eps} &\includegraphics[scale=2]{../../results/23/1_2.eps} &\includegraphics[scale=2]{../../results/23/1_3.eps} &\includegraphics[scale=2]{../../results/23/1_4.eps} &\includegraphics[scale=2]{../../results/23/1_5.eps} \\ \hline \end{tabular} \end{sidewaystable} I learn that the forloop package provides the for loop. But I am not sure how to apply it to my case? Or other methods not by forloop? Thanks and regards! Update: If I also want to simply another similar case, where the only difference is that the directory does not run from 1, 2, to 23, but in some arbitrary order such as 3, 2, 6, 9,..., or even a list of strings such as dira, dirc, dird, dirb,.... How to make the latex code into loops then? Thanks!

    Read the article

  • Mulitple variable containing "for loop" is not working in my code...

    - by OM The Eternity
    Below is the code I am working with and the last for loop i am iterating is not working... I think i am doing something wrong using multiple variable in a for loop,also I m aware of the fact that it can be done. $updaterbk = "SELECT j1. * FROM jos_audittrail j1 LEFT OUTER JOIN jos_audittrail j2 ON ( j1.trackid != j2.trackid AND j1.field != j2.field AND j1.changedone < j2.changedone ) WHERE j1.operation = 'UPDATE' AND j2.id IS NULL "; $selectupdrbk = mysql_query($updaterbk); while($row1 = mysql_fetch_array($selectupdrbk)) { $updrbk[] = $row1; } foreach($updrbk as $upfield) { if(!in_array($upfield['field'],$exist)) { $exist[] = $upfield['field']; $existval[] = $upfield['oldvalue']; //echo $updqueryrbk = "UPDATE `".$upfield['table_name']."` SET "; } } print_r($existval); for($i=0;$j=0;$i<count($exist);$j<count($existval);$i++;$j++) { $updqueryrbk.= $exist[$i]['field']."=".$existval[$j]['oldvalue'].","; $updqueryrbk.="="; $updqueryrbk.= $existval[$j]['oldvalue']; $updqueryrbk.=","; }

    Read the article

  • C# Console Application Output to .csv file

    - by Zinn
    I am trying to make a program that will show the numbers: 1, 10 +30 2, 40 (the scale goes up in this pattern by adding 20 to the last number added) 3, 90 +50 4, 160 5, 250 +70 So far I have this code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO;// namespace Myloop { class Program { static void Main(string[] args) /// </summary> { StreamWriter myOutputStream = new StreamWriter("loopdata.csv"); int forloop; for (forloop = 1; forloop < 21; forloop++) Console.WriteLine(forloop); Console.ReadLine(); myOutputStream.Close(); } } } This is showing the first sequence of numbers 1 - 20, but could anyone give me any guidance how to do the other sequence next to it in the console application and how I can output these to a .csv file, as the information I have so far doesn't appear in the .csv file

    Read the article

  • Attempt to use a while loop for the 'next' arg of a for loop generates #arg error

    - by JerryK
    Am attempting to teach myself to program using Tcl. The task i've set myself to motivate my learning of Tcl is to solve the 8 queens problem. My approach to creating a program is to successively 'prototype' a solution. I have asked an earlier question related to the correctly laying out the nested for loops and received a helpful answer. To my dismay I find that the next development of my code creates the same interpreter error : "wrong # args" I have been careful to have an open brace at the end of the line preceding the while loop command. I've also tried to put the arguments of the whileloop in braces. This generates a different error. I have sincerely tried to understand the Tcl syntax man page - not too successfully - suggested by the answerer of my earlier question. Here is the code set allowd 1 set notallowd 0 for {set r1p 1} {$r1p <= 8} {incr r1p } { puts "1st row q placed at $r1p" ;# re-initialize r2 'free for q placemnt' array after every change of r1 q pos: for {set i 1 } {$i <= 8} {incr i} { set r2($i) $allowd } for { set r2($r1p) $notallowd ; set r2([expr $r1p-1]) $notallowd ; set r2([expr $r1p+1]) $notallowd ; set r2p 1} {$r2p <= 8} { ;# 'next' arg of r2 forloop will be a whileloop : while r2($r2p)== $notallowd incr r2p } { puts "2nd row q placed at $r2p" ;# end of 'commnd' arg of r2 forloop } } Where am I going wrong? EDIT : to provide clear reply @slebetman As stated in my text, I did brace the arguments of the whileloop (indeed that was how i first wrote the code) below is exactly the layout of the r2 forloop tried: for { set r2($r1p) $notallowd ; set r2([expr $r1p-1]) $notallowd ; set r2([expr $r1p+1]) $notallowd ; set r2p 1} {$r2p <= 8} { ;# 'next' arg of r2 forloop will be a whileloop : while { r2($r2p)== $notallowd } { incr r2p } } { puts "2nd row q placed at $r2p" ;# end of 'commnd' arg of r2 forloop } but this generates the fatal interpreter error : "unknown math function 'r2' while compiling while { r2($r2p .... "

    Read the article

  • Windows Batch script - For /L not working -- simple

    - by XoronioX
    need some quick help. This is a university program, everything is working fine except when I call my :forLoop method to iterate through 100 numbers (1,1,100) starting at 1 going by 1 til 100 and doing the iteration % 5 (i%%5). for some reason I cannot get this to work. appreciate any help or direction. When I echo %%A it is iterating through all the number perfect. When I echo %result% I get a blank "" (nothing inside) :forLoop FOR /L %%A IN (1,1,100) DO ( set /A result=%%A %% 2 echo "%%A" echo "%result%" ) Correct code is :forLoop setlocal ENABLEDELAYEDEXPANSION FOR /L %%A IN (1,1,100) DO ( set /A result=%%A %% 5 echo !result! >> results.txt set /A total=!total!+!result! echo !total! )

    Read the article

  • Immutable values in F#

    - by rsteckly
    I'm just getting started in F# and have a basic question. Here's the code: let rec forLoop body times = if times <= 0 then () else body() forLoop body (times -1) I don't get the concept of how when you define a variable it is a value and immutable. Here, the value is changing in order to loop. How is that different from a variable in C#?

    Read the article

  • lscape and supertabular in Latex

    - by Tim
    Hi, I would like to put pictures into a supertabular table within lscape enviroment. The code is: \newcounter{themenumber} \newcounter{classnumber} \newcounter{imagenumber} \tablefirsthead{ \hline \backslashbox{Concept}{Class} &\multicolumn{3}{|c|}{Class 0} & \multicolumn{3}{|c|}{Class 1} \\ %\textbf{A} & \textbf{B}\\ \hline} \tablehead{ \hline \multicolumn{7}{|l|}{\small\sl continued from previous page}\\ \hline \backslashbox{Concept}{Class} &\multicolumn{3}{|c|}{Class 0} & \multicolumn{3}{|c|}{Class 1} \\ %\textbf{A} & \textbf{B}\\ \hline} \tabletail{ %\hline \multicolumn{7}{|l|}{\small\sl continued on next page}\\ \hline} \tablelasttail{} %\tablelasttail{\hline} \begin{landscape} \begin{supertabular}{| c || c | c | c || c | c | c |} \topcaption{Examples of All the Concepts. \label{tab:conceptsimgs}} \forloop{themenumber}{1}{\value{themenumber} < 24}{ \arabic{themenumber} \forloop{classnumber}{0}{\value{classnumber} < 2}{ \forloop{imagenumber}{1}{\value{imagenumber} < 4}{ & \includegraphics[scale=0.5]{../\arabic{themenumber}/\arabic{classnumber}_\arabic{imagenumber}.eps} } } \\ \hline } \end{supertabular} \end{landscape} However there is something wrong with the result: no caption is shown, the height of the part of table in each page exceeds the page height and there is something extra unwanted at the last page. See images below: page1 page2 page3 page4 How to fix the problems? Thanks and regards!

    Read the article

  • Intel IA-32 Assembly

    - by Kay
    I'm having a bit of difficulty converting the following java code into Intel IA-32 Assembly: class Person() { char name [8]; int age; void printName() {...} static void printAdults(Person [] list) { for(int k = 0; k < 100; k++){ if (list[k].age >= 18) { list[k].printName(); } } } } My attempt is: Person: push ebp; save callers ebp mov ebp, esp; setup new ebp push esi; esi will hold name push ebx; ebx will hold list push ecx; ecx will hold k init: mov esi, [ebp + 8]; mov ebx, [ebp + 12]; mov ecx, 0; k=0 forloop: cmp ecx, 100; jge end; if k>= 100 then break forloop cmp [ebx + 4 * ecx], 18 ; jl auxloop; if list[k].age < 18 then go to auxloop jmp printName; printName: auxloop: inc ecx; jmp forloop; end: pop ecx; pop ebx; pop esi; pop ebp; Is my code correct? NOTE: I'm not allowed to use global variables.

    Read the article

  • how to retrieve img alt text with jquery or javascript? [on hold]

    - by kate
    Which is the code with which we can retreive alternative text of image: It is a Cataloge with clothes. Dressers, Shirts, Skirts e.t.c. in front page of a site. The featured images of the categories can be changed manually from someone. I did a check and it is asking me to give alt text. I did it to some images with alt="". But to the cataloge I cannot do it. the code is below: {{ 'option_selection.js' | shopify_asset_url | script_tag }} {{ 'api.jquery.js' | shopify_asset_url | script_tag }} {% if template contains 'customers' %} {{ 'shopify_common.js' | shopify_asset_url | script_tag }} {{ 'customer_area.js' | shopify_asset_url | script_tag }} {% endif %} {% if settings.display_slideshow %}{{ 'jquery.slider.js' | asset_url | script_tag }}{% endif %} {% if settings.include_masonry %}{{ 'jquery.masonry.js' | asset_url | script_tag }}{% endif %} {% if settings.enable_product_image_zoom %}{{ 'jquery.zoom.js' | asset_url | script_tag }}{% endif %} {{ 'fancy.js' | asset_url | script_tag }} {{ 'shop.js' | asset_url | script_tag }} Shopify.money_format = '{{ shop.money_format }}'; {% if template contains "product" %} jQuery(document).ready(function($){ {% if product.variants.size 1 or product.options.size 1 %} new Shopify.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: selectCallback }); {% assign found_one_in_stock = false %} {% for variant in product.variants %} {% if variant.available and found_one_in_stock == false %} {% assign found_one_in_stock = true %} {% for option in product.options %} $('#product-select-option-' + {{ forloop.index0 }}).val({{ variant.options[forloop.index0] | json }}).trigger('change'); {% endfor %} {% endif %} {% endfor %} {% endif %} }); $(function() { $( "#tabs" ).tabs(); });

    Read the article

  • How can I return default at loop end in Scheme?

    - by Kufi Annan
    I'm trying to implement back-tracking search in Scheme. So far, I have the following: (define (backtrack n graph assignment) (cond (assignment-complete n assignment) (assignment) ) (define u (select-u graph assignment)) (define c 1) (define result 0) (let forLoop () (when (valid-choice graph assignment c) (hash-set! assignment u c) (set! result (backtrack n graph assignment)) (cond ((not (eq? result #f)) result)) (hash-remove! assignment u) ) (set! c (+ c 1)) (when (>= n c) (forLoop)) ) #f ) My functions assignment-complete and select-u pass unit tests. The argument assignment is a hash-table make with (make-hash), so it should be fine. I believe the problem I have is related to returning false at the end of the loop, if no recursive returns a non-false value (which should be a valid assignment).

    Read the article

  • How to prevent latex memory overflow

    - by drasto
    I've got a latex macro that makes small pictures. In that picture I need to draw area. Borders of that area are quadratic bezier curves and that area is to be filled. I did not know how to do it so currently I'm "filling" the area by drawing a plenty of bezier curves inside it... This slows down typeseting and when a macro is used multiple times (so tex is drawing really a lot of quadratic bezier curves) it produces following error: ! TeX capacity exceeded, sorry [main memory size=3000000]. How can I prevent this error ? (by freeing memory after macro or such...) Or even better how do I fill the area determined by two quadratic bezier curves? Code that produces error: \usepackage{forloop} \usepackage{picture} \usepackage{eepic} ... \linethickness{\lineThickness\unitlength}% \forloop[\lineThickness]{cy}{\cymin}{\value{cy} < \cymax}{% \qbezier(\ax, \ay)(\cx, \value{cy})(\bx, \by)% }% Here are some example values for variables: \setlength{\unitlength}{0.01pt} \lineThickness=20 %cy is just a counter - inital value is not important \cymin=450 \cymax=900 %from following only the difference between \ax and \bx is important \ax=0 \ay=0 \bx=550 \by=0 Note: To reproduce the error this code have to execute approximately 150 times (could be more depending on your latex memory settings). Thanks a lot for any help

    Read the article

  • Attempt to create nested for loops generating missing arguments error

    - by JerryK
    Am attempting to teach myself to program using Tcl. (I want to become more familiar with the language to understand someone else's code - SCID chess) The task i've set myself to motivate my learing of Tcl is to solve the 8 queens problem. My approach to creating a program is to sucessively 'prototype' a solution. So. I'm up to nesting a for loop holding the q pos on row 2 inside the for loop holding the q pos on row 1 Here is my code set allowd 1 set notallowd 0 for {set r1p 1} {$r1p <= 8} {incr r1p } { puts "1st row q placed at $r1p" ;# re-initialize r2 'free for q placemnt' array after every change of r1 q pos: for {set i 1 } {$i <= 8} {incr i} { set r2($i) $allowd } for { set r2($r1p) $notallowd ; set r2([eval $r1p-1]) $notallowd ; set r2([eval $r1p+1]) $notallowd ; set r2p 1} {$r2p <= 8} { incr r2p ;# end of 'next' arg of r2 forloop } ;# commnd arg of r2 forloop placed below: {puts "2nd row q placed at $r2p" } } My problem is that when i run the code the interpreter is aborting with the fatal error: "wrong #args should be for start test next command. I've gone over my code a few times and can't see that i've missed any of the for loop arguments.

    Read the article

  • How to represent "{{" in a django template?

    - by rxin
    I'm trying to output in bibtex format in Django and the template looks like this: @{{ pubentry.type }{, author = {{% for author in pubentry.authors.all %}{{ author.first_name }} {{ author.middle_name }} {{ author.last_name }}{% if not forloop.last %} and {% endif %} {% endfor %}}, title = {{{ pubentry.title }}}, journal = {{{ pubentry.journal }}} } The problem is with the "{{{" or "{{%". One way to go around the problem is to add a space after the first "{", but that kind of tamper the format. What's the right way to escape { in Django templates?

    Read the article

  • fancybox image sometimes renders outside box

    - by Colleen
    I have the following django template: <script type="text/javascript" src="{{ STATIC_URL }}js/ jquery.fancybox-1.3.4.pack.js"></script> <link rel="stylesheet" href="{{ STATIC_URL }}css/ jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> {% include "submission-form.html" with section="photos" %} <div class="commentables"> {% load thumbnail %} {% for story in objects %} <div class="image {% if forloop.counter|add:"-1"| divisibleby:picsinrow %}left{% else %}{% if forloop.counter| divisibleby:picsinrow %}right{% else %}middle{% endif %}{% endif %}"> {% if story.image %} {% thumbnail story.image size crop="center" as full_im %} <a rel="gallery" href="{% url post slug=story.slug %}"> <img class="preview" {% if story.title %} alt="{{ story.title }}" {% endif %} src="{{ full_im.url }}" full- image="{% if story.image_url %}{{ story.image_url }}{% else %} {{ story.image.url }}{% endif %}"> </a> {% endthumbnail %} {% else %} {% if story.image_url %} {% thumbnail story.image_url size crop="center" as full_im %} <a rel="gallery" href="{% url post slug=story.slug %}"> <img class="preview" {% if story.title %} alt="{{ story.title }}" {% endif %} src="{{ full_im.url }}" full- image="{{ story.image_url }}"> </a> {% endthumbnail %} {% endif %} {% endif %} </div> {% endfor %} {% if rowid != "last" %} <br style="clear: both" /> {% endif %} {% if not no_more_button %} <p style="text-align: right;" class="more-results"><a href="{% url images school_slug tag_slug %}">more...</a></p> {% endif %} </div> <script> $(document).ready(function(){ function changeattr(e){ var f = $(e.clone()); $(f.children()[0]).attr('src', $(f.children() [0]).attr("full-image")); $(f.children()[0]).attr('height', '500px'); return f[0].outerHTML; } $('.image a').each(function(idx, elem) { var e = $(elem); e.fancybox({ title: $(e.children()[0]).attr('alt'), content: changeattr(e) }); }); }); </script> and I'm occasionally getting weird display errors where the box will either not render anything at all (so it will show up as just a thin white bar, basically) or it will render only about 30 px wide, and position itself halfway down the page. In both cases, if I inspect element, I can see the "shadow" of the full picture, at the right size, with the right url. Image source doesnt' seem to make a difference, I'm getting no errors, and this is happening in both chrome and firefox. Does anyone have any ideas?

    Read the article

  • Django templates crashes with no sense

    - by user233323
    Hello I'm trying to use google visualization API along with django templates system. I got an error that don't know how to fix. The error is the following: invalid_block_tag raise self.error(token, "Invalid block tag: '%s'" % command) django.template.TemplateSyntaxError: Invalid block tag: 'endfor' The code is: function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('date', 'time'); data.addColumn('number', 'x'); data.addColumn('number', 'y'); data.addColumn('number', 'z'); data.addRows([ {% for d in datos &} [new Date({{d.instante|date:"Y, m, d, H, i, s"}}), {{d.x}}, {{d.y}}, {{d.z}}] {% if not forloop.last %},{% endif %} ]); {% endfor %} var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div')); chart.draw(data, {displayAnnotations: true}); } Thanks you all!

    Read the article

  • Sorting a string array in C++ no matter of A or a and with å, ä ö?

    - by Chris_45
    How do you sort an array of strings in C++ that will make this happen in this order: mr Anka Mr broWn mr Ceaser mR donK mr ålish Mr Ätt mr önD //following not the way to get that order regardeless upper or lowercase and å, ä, ö //in forloop... string handle; point1 = array1[j].find_first_of(' '); string forename1(array1[j].substr(0, (point1))); string aftername1(array1[j].substr(point1 + 1)); point2 = array1[j+1].find_first_of(' '); string forename2(array1[j+1].substr(0, (point2))); string aftername2(array1[j+1].substr(point2 + 1)); if(aftername1 > aftername2){ handle = array1[j]; array1[j] = array1[j+1]; array1[j+1] = handle;//swapping } if(aftername1 == aftername2){ if(forname1 > forname2){ handle = array1[j]; array1[j] = array1[j+1]; array1[j+1] = handle; } }

    Read the article

  • Sorting and indexing into a list in a Django template?

    - by slypete
    How can you perform complex sorting on an object before passing it to the template? For example, here is my view: @login_required def overview(request): physicians = PhysicianGroup.objects.get(pk=physician_group).physicians for physician in physicians.all(): physician.service_patients.order_by('bed__room__unit', 'bed__room__order', 'bed__order') return render_to_response('hospitalists/overview.html', RequestContext(request, {'physicians': physicians,})) The physicians object is not ordered correctly in the template. Why not? Additionally, how do you index into a list inside the template? For example, (this doesn't work): {% for note_type in note_types %} <div><h3>{{ note_type }}</h3> {% for notes in note_sets.index(parent.forloop.counter0) %} #only want to display the notes of this note_type! {% for note in notes %} <p>{{ note }}</p> {% endfor %} {% endfor %} </div> {% endfor %}

    Read the article

  • javascript increment index in funciton

    - by mcgrailm
    I'm just trying to figure out how to create an index inside a function so I can keep track of the items its generating and I'm not sure how to do this seems like I should know this.. addLocation(options,location) funciton addLocation(options,location){ $('#list').append('<li class="location"><div>'+location.label+'</div>'+ '<input type="hidden" name="location['+x+'][lat]" value="'+location.lat+'" />'+ '<input type="hidden" name="location['+x+'][lon]" value="'+location.lon+'" />'+ '<input type="hidden" name="location['+x+'][loc]" value="'+location.loc+'" />'+ '<input type="hidden" name="location['+x+'][label]" value="'+location.label+'" />'+ '</li>'); } now normally you have a forloop to help you keep track of things but int this instance I'm not appending items in a loop and I keep getting an error saying x in undefined appreciate any help you can give thanks Mike

    Read the article

  • django generic view not recieving an object (template issue?)

    - by Kirby
    My Model class Player(models.Model): player_name = models.CharField(max_length=50) player_email = models.CharField(max_length=50) def __unicode__(self): return self.player_name My Root urls.py urlpatterns = patterns('', (r'^kroster/', include('djangosite.kroster.urls')), (r'^admin/(.*)', admin.site.root), ) My kroster urls.py from djangosite.kroster.models import Player info_dict = { 'queryset': Player.objects.all(), } urlpatterns = patterns('', (r'^$', 'django.views.generic.list_detail.object_list', info_dict), (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict), ) My player_list.html template <h1>Player List</h1> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} <ul> {% for player in object.player_set.all %} <li id="{{ player.id }}">{{ forloop.counter }} .)&nbsp;&nbsp;{{ player }}</li> {% endfor %} </ul> Sadly my template output is this. <h1>Player List</h1> <ul> </ul> Apologies if this is a stupid mistake. It has to be something wrong w/ my template.

    Read the article

1 2  | Next Page >