Creating A For Loop Inside Another For Loop.
I'm trying to write a script that will display questions that are in one flat file and answers from another flat file. In addition, there are copies of these files with their own data in multiple folders.
I created a for loop to work with an array of the different file paths to the different folders. Then I created a for loop inside of that one to display the questions and answers files that is in each folder. All I get when I run the script is the first folder and it's questions and then it stops there. PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Creating Table Rows For Ever Other Loop In A WHILE Loop
I'm trying to create a table using a MySQL fetch array while loop that would look like this: CONTENT1 CONTENT2 CONTENT3 CONTENT4 CONTENT5 CONTENT6 I need a <TR></TR> for every other piece of content. But I don't know how to do this with a loop that uses a MySQL fetch array while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { PHP CODE THAT IS LOOPED;}; I'm trying to remember from my old college Java class that we did something with loops for whenever the counter variable was even the loop would do something special... I don't know if this is possible with a while+mysql_fetch_array loop though.
If Statement Inside For Loop
Trying to build a script that sets selected if that is the value in the database (script modefied with static values for forum.) What is does is make a dropdown box according to the number in stock, then it should selected the number that the customer has already selected. The error is that it adds 'selected' to all values.
Getting Maximum Value Inside A Loop
I'm using something like this, to output a table of rows: // Set max_val $max_val = 0; // Do the loop while ($row = mysql_fetch_assoc($result)) { $max_val = max($max_val, $row['integer']); // etc etc echo $max_val; // etc etc } I want the maximum value of $row['integer'] to be available in every row. The above example does this, with the exception of the first (top) row of the table, where $max_val is then the value of $row['integer'] for that row - not the actual maximum for all rows.
UPDATE Inside A WHILE Loop
I have a WHILE loop that steps through a set of retrieved records, depending on the status of a checkbox from a form, specific records will be updated. Problem is I get an error "Warning: Supplied argument is not a valid MySQL result resource in codetest.php on line xxx" PHP Code:
Queries Inside A Loop
Can you create queries inside a loop? Probably in a 'do while' loop. The problem I've hit is that I have a web app for a sports team. On one page we enter how many tries(touchdowns) they scored, and then this number of drop-down menus appears on the next page, filled with all the possible players. The user then selects the players who scored and submits the form. This action should then create a new record in the 'tries' table for each try scored (in other words, for each drop-down menu). I've got it so that I can create one try automatically using the code below, but is there a way I can loop this so it repeats for every try? I've named them try1, try2, etc. $createtry_sql = sprintf("INSERT into tries (tryOpponent, tryTeam, trySeason, tryPlayer) VALUES ('%s', '%s', '%s', '%s')", $_SESSION['creatematch']['opposition'], $_SESSION['creatematch']['ottersteam'], $_SESSION['creatematch']['season'], $_POST['try1'] ); $createtry_query = mysql_query($createtry_sql) or die(mysql_error());
Recall A Function Inside A Loop
I'm running through two arrays making sure the values do not match each other and if one value in array b does match a value in array a, what I want to happen is: foreach($arrayb as $key => $value){ if($value == $array[$getrandnumb]){ $getrandnumb = getrandnumb($result); // I want to recall this function to get another number // but it needs to jump OUT of this foreach loop so it can then // be run again. $taken = 1; } else { $taken = 0; } } How can I do this?
Variables Inside A Foreach Loop
I have two arrays that have Spring and Fall specific dates. They do exactly what I want but, when I put them on the same page, the first array, Spring months, prints out then the second array, Fall months, prints out and then the first array prints out again. Its not supposed to do that at all. However, I dont see what is causing the second printing of the first array. Here are the two arrays.....
Using Mysql UPDATE Inside For Loop
I have an array that stores pieces of information that I want to update to a database. I decided to use the for loop to retrieve the peices of information and one by one store them into the database. The last peice of the array is stored repeatedly for the other values.... I have echoed the process the loop takes and i cannot figure out the problem... Here is a simplified version of my code:
Form Inside Loop, Need To Wait Till Submit Is Activated.
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform' action='ins_op.php' method='post'>"; lots of form stuff echo "<td><input type='submit' value='Save'>"; echo "</form>"; } I'd like to have the loop wait until the form submit is pressed before it continues and grabs the next record from $row_array. Right now the code displays all the records with their submit buttons. Doing it in this form permits one query to the database to get all the open records.
Creating A Monitoring / Querying Loop
Is it possible to create a loop in PHP, embedded in a web page, that periodically queries another program (like a web service for example), and correspondingly updates the information on the web page?
Technique For Creating Variables Within A Loop
I'm reasonably proficient in PHP but have been asked how to do something which has got me stumped. Hence, my posting: I want to create a small number of variables, $pos1, $pos2 ... $pos5 within a loop and assign them values from an array, but creating the variable names with incrementing numbers, well I've no idea how the PHP syntax for it works. ========== START CODE ========== <?php $x=5; $myarray = array('a','b','c','d','e'); for($a=0;$a<$x;$a++){ $pos.$a = $myarray[$a]; //Create $pos0 here on first loop, // $pos1 next loop and so forth.. } //Test assigned variable echo $pos3; // $pos3 should equal 'd' exit; ?> ========== END CODE ==========
Creating An Object Inside A Class
is it possible to create an object inside a class?... say i have 2 class... class a { var $val; some code } class b { $myobject = new a; $myobject->val=1; ............... } will the above work ??... first of all .. is it possible to do like above ?
For Loop In PHP
I am trying to print a HTML table using PHP (with a countdown counter) but I do not see the table being display. Can someone highlight the error i m making ... <?php $input=8; print $input; print "<table border=3 bordercolor=0084A5>"; for ($cnt=$input+1 ; $cnt = 1 ; $cnt=$cnt-1) { print "<tr>"; print "<td>$cnt</td>"; print "</tr>"; } print "</table>"; ?>
Help In Loop For
Suppose I have this: for($i = 0; $i < count($data); $i++){ $blocked = isBlockedForMe($my_id, $account_id); // true or false } I want when the $blocked is true to SKIP to the next step, I dont want to BREAK, I want something like this: for($i = 0; $i < count($data); $i++){ $blocked = isBlockedForMe($my_id, $account_id); // true or false if($blocked){ ....SOMETHING HERE TO SKIP but continue in the loop } // I dont want to show/execute what is below ............ ............ }
For Loop Q
I have a "for loop". In this "for loop" a variable called $reg is set. Each iteration of the "for loop", $reg is assigned to a new value. My question is: how I can store the values of $reg each iteration in an array? Below is some pseudocode, which I hope further illustrates what I mean. $count = 60; for ($i = 1; $i <= $count; ++$i) { $reg = } This has got me a bit stumped. After I have managed to make the array. I would then like to explode this array out into variables - each one assigned a value of $reg I realise that this may be quite a basic Q. And i really do apoligise. I have read up on arrays and am having trouble applying it to this situation. Thanks very much. P.S A further complication that I would like to accommodate is that $reg may be assigned a number of values in a single "for loop". I would like to collect all these values. The pseudocode for this: $count = 60; for ($i = 1; $i <= $count; ++$i) { $reg = $reg = } If this post is difficult to follow - dont hesitate to post back and I will try my best to expand. It is just I didnt want to make this post too long and put people off. P.S It may be helpful to know what is actually in the "for loop": for() { $regex = "/(([A-Za-z0-9]+_+)?[A-Za-z0-9]+-+)?[A-Za-z0-9]+.+)?[A-Z a-z0-9]+++))*[A-Za-z0-9]+@((w+-+)?w+.))*w{1,63}.[a-z A-Z]{2,6}/"; preg_match_all($regex, $data, $reg)) }
If/Then In A While Loop
I tried a bunch of different things, but am I able to do an if/then within a while loop? Here is the code that I am basically trying to do... PHP Code:
While Loop...
I've been working on a relatively simple function, that just won't work. Here it is: PHP Code:
For Loop Or While Loop
I was wondering if this could be achieved with a for loop or a while loop basically returning the time for up to 20 years: PHP Code:
While Loop
I have a while loop thats get comments on news articles from a database. I am using a class as my database connection method. It only gets the first record. Here is my code:
$i++ Loop
What I'm trying to do is echo a error message if a field(s) is left blank without having to do alot of if statements. The code I have now works but will only show one number at a time. PHP Code:
For Loop?
I'm trying to limit the number of cells in a table to 4 across echo "<table border=1>"; echo "<tr>"; while($result = mysql_fetch_array($sql)){ echo "<td><IMG SRC="$result[photo]""></td>";} echo "</tr>"; echo "</table>"; so if there are 15 entries in the db, it gives me 15 cells in one row. How can i limit the cells in a row to 4, and have it generate however many rows to display all. I've been experimenting with for loops, but no luck.
Loop Through JS Using Php?
I am trying to loop through a JS script as below using php to get the contents for a drop down list but I cant seem to get the loop to work. Here's what I have been trying.. // Heres the JS for the drop down list. I cant have this static as it is here as there could be 10-20 results in the drop down list so I need to loop through my DB result and loop the below script also Code:
LOOP IN A LOOP
I am making a navigation system for a website and I want all the links to be in a table on a database so that the links can easily be added to or subtracted from when found necessary. The way the navigation works is that it is a horizontal navbar with drop down menus filled with sub categories Code:
Using A While Loop In A For Loop - Can This Be Done?
can you use a while loop inside a for loop; without contradicting or excluding your for loop? I would test it myself; except my server is having Server Error 500 issues right now. so I am not able to do a trial and error test at this time. something like this: for ($x = $skip2;$x<=$pagedisplay;$x++){ while ($myfield != $maxed_out) { echo " <a href="". $_SERVER['PHP_SELF'] ."?skip=$x">". ($x+1) ."</a> "; } }
For Loop
I work mostly with flash but use php to talk to databases so I am not strong in php. I am passing some variables from flash that I want to add to a database. They are in the form of sid0=A&sid1=B&sid2=C and so on, n is the total number of variables passed. I believe the server I am working on uses PHP 4.1. Code:
Loop
How can I make a loop for this formula? P (1 + r/365)365
Loop Only Gets 1 Value!
And it kicks out the results on the page in hyperlinks, all the zipid's are 14, they should be looping through and getting the search_id that matches the zipcode. Code:
While Loop And Div
I have some code which loops whilst there are some results in the database. These are displayed inside a while loop. However any div inside the loop does not display. Code:
While Loop
I´m trying to make an application to insert new data into a table. So i extract the fields of the table and let the user introduce new values. The problem is when i´m trying to put them into a table. Firstly i get the new data sent via form with a while loop, because the number anda name of the fields can be different in each case. I do it like this $sql = " SHOW COLUMNS FROM " .$_SESSION["nomtab"]. " "; $res= mysql_query($sql); while($row = mysql_fetch_array($res)) { $$row[0] = $_POST["$row[0]"]; } Now i introduce correctly the first´s field value and i create two auxiliar variables $primercampo and $valorprimercampo which contains the name of the first field and its value, so i can use them later to update the values, it goes like that Code:
Loop
I'm trying to add the following link to my display page. <a href="applyforstake.php?item_id=1>Apply" This is the code taken directly from the display page: echo "<td>"."<a href="applyforstake.php?item_id=1">Apply"."</td>"; This code works well for displaying the link in my display page, however, I want the item_id to be equal to the auto_increment column on each row. In other words, for the first row on the display page, the item_id will be 1, the second row item_id should be 2 and so on for however many rows are in the table. How do I accomplish this.
For Loop And Arrays
I'm trying to create a function to execute multiple backups at once, using the following code:
While Loop Timing Out
Ok I just ran into this problem. I have a while statment going and the server will time it out because it going to long does anyone know a way around this? I found somewhere online that says that PHP times out a while loop after a certan amount of time even if you have set_time_limit() or set it in the php.ini file. For somethings I can just make it break after a number of loops and start back where it was but can't do it on some things.
How To Loop Query
I want to display all the values from certain row, how do i query and use loop so it will display all the value?
Horizontal Loop
I'm building a php form that retrieves about 25 categories from a MySQL database and creates a list of check boxes so users can select multiple categories before submitting the form. Right now I'm using the code below and it creates a vertical list of categories with check boxes.
Txt File Loop
How would I go about making a loop to open a .txt file, read the first line, then do something with it and them loop to the next line.
For Loop With Txt Files
I want to do a for-loop on all files within a directory... pseudo-code example: for ($filename is each possible file) { Do stuff with the $filename; } What should the for-loop look like or is there another way to acces each file seperately?
Loop Every Ten Seconds
Is it possible to get something to repeat every x number of seconds, like cron but i need it as a function of the actual script.
Loop Through A List
I want to loop through a list and display it in a table with three columns per row, yet haven't had much luck in doing so. I was thinking if would be something like so Quote: for ($x = 0; $x < mysql_num_rows($query); $x++) { if ($x / 3) { ?> <tr> <? } ?><td> Blah </td></tr></table> Well, that's as much as I know so far.
For Loop And Arrays
I'm trying to run through an array which has each value in element 1-3. For example: for($x=1;$x<3;$x++){ echo "$array[$x]" } Is this not valid code, because it doesn't seem to work. Also, is there another way to do this?
2 Values In A Loop
In a guestbook the im building, I want to set the <tr> bgcolor in a difrent color each msg (the same effect is also here in these forums).The code is a while loop (to get mysql results). How can I do it ?
While Loop From Array
I have an array, let's call it $namesarray which is full of names. How do I create a loop such as a while loop to repeat for every value (name) in the array?
Conditional Loop
I have one table, "players" that has player info including start season (year). I then have a table for each season with player stats, i.e. games played etc called stats200X where X is the year obviously. I have no problem with extracting data from the current year, but what I would like to do is get data from previous years too. I was thinking about doing something like: (year) - (startyear), which for example could be 3. I don't know where to begin, but I want to be able to loop though previous years so that, if tables exist of course, I could do select * from stats{Y -1} display select * from stats{Y -2} etc Would I need to hard code this or is there a way of doing this though a conditional loop?
For Loop Problems
Anyway, I'm trying to make it so that 3 columns of links will show up on a page so link1 link2 link3 link4 link5 link6 link7 link8 link9 etc. I've got this code for it, but I get an error message if the number of links in the database isn't an integer divided by three. So if it's not 3,6,9,12, etc. I get Warning: mysql_result(): Unable to jump to row 4 on MySQL result index 3 in mydirectory/loop.php on line 14 I'd like it to stop if there is a number not divisible by 3, but I'm guessing it just keeps going. here's the code. for ($i = 0; $i < mysql_num_rows($result);) { echo '<table align="center" cellpadding="0" cellspacing="0" width="90%"<tr>' for ($a = 0; $a < 3; $a++) { $articlename = mysql_result($result, $i, "articlename"); $articletitle = mysql_result($result, $i, "articletitle"); $i++; echo '<td width="33%" align="center" valign="top"<p><a href="/articles/' . $articlename . '/articles.php">' . $articletitle ..'</a></p</td>' } echo '</tr></table><br>' }
Stop A For Loop
I have been messing around with a tutor I found on phpFreaks.com (http://www.phpfreaks.com/tutorials/73/0.php) and what I would like to know is how to stop the for loop for the other pages going over 10. This it the pices of code which loops to links to the other pages but I don't want it to loop any more than 10 times? PHP Code:
|