Posts

Showing posts with the label loops

Adding a “No Results Found” to a search filter output page

Image
Clash Royale CLAN TAG #URR8PPP Adding a “No Results Found” to a search filter output page Having a bit of a mare with a custom template. I have a filter which works well, unfortunately when it yields no results there's no indication that no results have been found. Im trying to display "No results found" when there's nothing to show... I'm under the impression that the answer is going to be something along the lines of adding this to the end of the hook <?php else : ?> <p>There are no results</p> <?php endif ?> My php knowledge is minimal, stubbornly i've spent approx 2 days trying to fix after reading upon others solutions with no luck, i'm wondering if someone could shed a little light or if it can even be achieved. Here's the current code............. <?php if (!defined('ABSPATH')) die('No direct access allowed'); ?> <?php wp_enqueue_style('my_kitchensnew3', get_template_directory_uri() . ...

How to output a group, based on the same column cell, while looping it out into html?

Image
Clash Royale CLAN TAG #URR8PPP How to output a group, based on the same column cell, while looping it out into html? I want to create groups while looping all my rows from a database table. example database: id | sex | name | age 1 | male | kevin | 20 2 | male | bob | 24 3 | female | jenny | 24 4 | female | bob | 20 5 | no | gaben | 13 I want to group the entries by names. The output i'm looking for is something like this: Should output: <div id="bob"> <a>bob male 24</a> <a>bob female 20</a> </div> <div id="kevin"> <a>kevin male 20</a> </div> <div id="gaben"> <a>gaben no 13</a> </div> <div id="jenny"> <a>jenny female 24</a> </div> I was making two while loops inside of eachother. It only outputs one <div> for one name . Each div should be created for each unique name . So when someone has the same name , they should be put t...

For loop with Maxima

Image
Clash Royale CLAN TAG #URR8PPP For loop with Maxima for i:1 thru 3 step 1 do; posix:arithsum(li*cos(ri(t))),1,i-1)+(li*cos(ri(t))/2); posiy:arithsum(li*sin(ri(t))),1,i-1)+(li*sin(ri(t))/2); What I wanna do is to get 6 position functions(3 x and 3 y). It should give me values like following: pos1x:l1*cos(r1(t))/2; pos2x:l1*cos(r1(t))+l2*cos(r2(t))/2; pos3x:l1*cos(r1(t))+l2*cos(r2(t))+l3*cos(r3(t))/2; So, why my code is not working? 1 Answer 1 Couple of things here. (1) for loop takes just one expression as its loop body; typically multiple expressions are combined into one as (e1, e2, e3) or block(e1, e2, e3) . Note that for ... do; isn't correct syntax, since it doesn't have a loop body -- the semicolon terminates the for expression. Note also that expressions in the body are separated by commas, not semicolons. (2) You can use subscript notation to index items; Maxima won't automati...

Loop to identify data location in a Dataframe, and populate to new Dataframe (R)

Image
Clash Royale CLAN TAG #URR8PPP Loop to identify data location in a Dataframe, and populate to new Dataframe (R) So I have a dataframe of user IDs as columns with rows (corresponding to period intervals) with binary variables (where an event happened) like this: date Id1 Id2 id3 id4 id5 row1 1 0 0 1 0 row2 0 0 1 1 0 row3 0 1 0 0 1 row4 1 1 0 0 0 row5 0 0 1 1 1 ... I am trying to build a loop that runs through each row of each column which identifies any cell with a 1 and populates a new data frame with the row number of each occurrence, e.g: occ. Id1 Id2 id3 id4 id5 1 1 3 2 1 3 2 4 4 5 2 5 3 5 4 5 I am pretty lost in how to approach this, if anyone is able to help? Your second frame isn't really a frame since you have different lengths of each column. Additionally, your sample frames don't match, can you edit your question to make them representative?...

Python Script to loop through and create variables

Image
Clash Royale CLAN TAG #URR8PPP Python Script to loop through and create variables I have a massive block of code that creates the following arrays (Var1 ... Var100). I was wondering if there is way to actually write a python script to create and execute the code within a for loop. However, I've been unsuccessful so far in doing so. Var1 = np.where((df['Q_1'] * df['CapR1'])>=(1*df['CapR1']),df['CapR1'],0) Var2 = np.where((df['Q_2'] * df['CapR2'])>=(1*df['CapR2']),df['CapR2'],0) ... Var100 = np.where((df['Q_100'] * df['CapR100'])>=(1*df['CapR100']),df['CapR100'],0) I've tried the following but doesn't work: for i in range(1,101): 'Var' + str(i) = np.where((df['Q_' + str(i)] * df['CapR' + str(i)])>=(1*df['CapR' + str(i)]),df['CapR' + str(i)],0) By clicking ...

Transfer control to outermost loop python for each iteration

Image
Clash Royale CLAN TAG #URR8PPP Transfer control to outermost loop python for each iteration Consider the code for i in range(1,3): print(i) for j in range(4,7): print(j) for k in range(8,10): print(k) continue the expected output is [1 4 8 9] and [2 5 8 9] [1 4 8 9] and [2 5 8 9] for each iteration and actual is [1 4 8 9 ],[5 8 9],[6 8 9],[2 4 8 9],[5 8 9],[6 8 9] [1 4 8 9 ],[5 8 9],[6 8 9],[2 4 8 9],[5 8 9],[6 8 9] By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Error in function to create heatmap using ggplot2

Image
Clash Royale CLAN TAG #URR8PPP Error in function to create heatmap using ggplot2 I'm trying to make a heatmap using ggplot2. What I want to be plotted is in the form of a matrix which is the result of a function. Here is the data: Here is the function: vector_a <- names(master)[2:4] vector_b <- names(master)[5:6] heatmap_prep <- function(dataframe, vector_a,vector_b){ dummy <- as.data.frame(matrix(0, nrow=length(vector_a), ncol=length(vector_b))) for (i in 1:length(vector_a)){ first_value <- dataframe[[ vector_a[i] ]] # print(first_value) for(j in 1:length(vector_b)){ second_value <- dataframe[[ vector_b[j] ]] result <- cor(first_value, second_value, method = "spearman") dummy [i,j] <- result } } rownames(dummy) <- vector_a return(as.matrix(dummy)) heatmap_data_matrix1 <- heatmap_prep(master,vector_a, vector_b) Using the data in h...

NoSuchElementException in simple User Input loop Java 8 [on hold]

Image
Clash Royale CLAN TAG #URR8PPP NoSuchElementException in simple User Input loop Java 8 [on hold] I've looked around here a lot and haven't found an answer to my problem. I get the exception at "return in13.nextInt()". I've tried a lot of different ways of doing this "play again" thing, that's why right now I have an "int" value for it. I'd be very happy if someone showed me the best way to add this feature to my text game! Edit: This got reported for being "off-topic" because I didn't say what want the code to do, apparently. I want getPlayAgain() to run after game() runs until "user" inputs an integer other than 1. (I'm a beginner at Java) private static Scanner in13; public static void main(String args) { do { game(); } while(getPlayAgain() == 1); in13.close(); } public static int getPlayAgain() { in13 = new Scanner(System.in); ...