while-loop

mysql select with while loop

送分小仙女□ 提交于 2020-01-03 06:37:11
问题 I would like to select data from my table and using one of the columns, create a loop to define additional data. For example: 'select id,related_id,name from ancestors' id, related_id, name 1, 0, Bob 2, 1, Dave 3, 2, Susie 4, 1, Luke 5, 0, Cindy 6, 5, Sam Bob is the grandfather, Dave and Luke are his children and Susie is his granddaughter. Cindy has a child Sam. Now, I want to use related_id to figure out how many levels the ancestor tree goes down. So I want the results to be: id, related

script(while-loop) stops and has no ouput when multiple columns are selected

本小妞迷上赌 提交于 2020-01-03 06:32:06
问题 I want to select more than one columns from TABLE but the script is not working once the while loop starts. my php and html code is: <table border="0"> include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ; $sql="select post_title,post_desc,post_date,course,semester,firstname,lastname FROM wbut_forum_posts left join users on post_by = email ORDER BY post_id DESC LIMIT 25"; $result = mysqli_query($link,$sql ); if (!$result) { include_once "wall.html.php"; echo'<tr><td align="center">

Reset Counter in While Loop

假如想象 提交于 2020-01-03 06:29:14
问题 I would like to reset counter in the following loop. Have no idea how to do it $j = 1; while($row = mysqli_fetch_array($check)) { $value = $row['tmpi']; $calculate = mysqli_query($link,"SELECT * FROM tmpi_db WHERE tmpi_id = '".value."'"); $action = mysqli_num_rows($calculate); if($j == $action) { //RESET $j, $j must be one again, nothing is working I have tried $j = 1; //It's keep incrementing 1,2,3,4,5,6,7..... } } $j++ Please help 回答1: Something like this should work. Simply start at zero,

Shuffle an array of int in C with - without while loop

大城市里の小女人 提交于 2020-01-03 05:29:07
问题 I want to Shuffle an array of ints, the array is sorted and its size in n, values are 1 - n. I Just want to avoid using a while loop in order to make sure the rand() doesn't give me the same index. the code looks somthin like this: void shuffleArr(int* arr, size_t n) { int newIndx = 0; int i = 0; for(; i < n - 1; ++i) { while((newIndx = i + rand() % (n - i)) == i); swap(i, newIndx, arr); } } The for loop goes until n-1, so for example in the last run it has 50/50 chance of being equal to i. I

Use python to crawl a website

痞子三分冷 提交于 2020-01-03 04:45:49
问题 So I am looking for a dynamic way to crawl a website and grab links from each page. I decided to experiment with Beauitfulsoup. Two questions: How do I do this more dynamically then using nested while statements searching for links. I want to get all the links from this site. But I don't want to continue to put nested while loops. topLevelLinks = self.getAllUniqueLinks(baseUrl) listOfLinks = list(topLevelLinks) length = len(listOfLinks) count = 0 while(count < length): twoLevelLinks = self

1 + 1 / 2! + 1/ 3! + ¼! + …… Finding Sum [duplicate]

纵然是瞬间 提交于 2020-01-03 04:38:45
问题 This question already has answers here : How can I force division to be floating point? Division keeps rounding down to 0? (11 answers) Closed 4 years ago . Q. ) 1 + 1 / 2! + 1/ 3! + ¼! + …..... The output of the following program is always 1.0. I'm a python beginner. Please tell me what's wrong? Please suggest any other methods to make this program better. No inbuilt functions, please. I want to do this manually. n=int(raw_input("Enter number of terms : ")) d=0 #to sum all terms, initial

How to add case statement to add break after every record?

旧时模样 提交于 2020-01-02 10:07:24
问题 There should be a break after every row LIKE 'A%' when find next records of LIKE 'B%' . $stmt = $con->prepare("SELECT * FROM fistevent WHERE Event_Id=? AND TicketType=? AND row_name REGEXP '^[A-Z]' ORDER BY row_name ASC"); $stmt->bind_param("ss", $_POST['EventId'],$_POST['TicketType']); $stmt->execute(); $result = $stmt->get_result(); $numRows = $result->num_rows; if($numRows > 0) { echo ' <div class="register">'; while($r = $result->fetch_assoc()) { $EvntId = $r['Event_Id']; $RowName = $r[

How can I make Selenium click on the “Next” button until it is no longer possible?

故事扮演 提交于 2020-01-02 07:03:30
问题 I would like to write a code that would make Python scrape some data on a page, then click on the "next" button at the bottom of the page, scrape some data on the second page, click on the "next" button, etc. until the last page, where clicking on "Next" is no longer possible (because there is no "next"). I would like to make the code as general as possible and not specify beforehand the number of clicks to be done. Following this question (How can I make Selenium click through a variable

Recursion inside while loop, How does it work?

邮差的信 提交于 2020-01-02 06:21:40
问题 Can you please tell me how does this java code work? : public class Main { public static void main (String[] args) { Strangemethod(5); } public static void Strangemethod(int len) { while(len > 1){ System.out.println(len-1); Strangemethod(len - 1); } } } I tried to debug it and follow the code step by step but I didn't understand it. update: sorry I didn't mention that I know the result of this code but just want to know the steps of the execution.. 回答1: That'll print 4 3 2 1 1 1 1 1 1... And

Pythonic enumeration of while loop

萝らか妹 提交于 2020-01-02 02:11:48
问题 Python has an elegant way of automatically generating a counter variable in for loops: the enumerate function. This saves the need of initializing and incrementing a counter variable. Counter variables are also ugly because they are often useless once the loop is finished, yet their scope is not the scope of the loop, so they occupy the namespace without need (although I am not sure whether enumerate actually solves this). My question is, whether there is a similar pythonic solution for while