PHP - For Loop To Increment Day By One Each Iteration Not Working As Expected
I am doing some study on using time() and date() and i just wrote this simple for loop to add one day to each iteration with +$i and its echoing the unix timestamp as opposed to the correctly formated date as it should be based on my code. Anyone have any idea why this is not working as expected?
for($i=0; $i < 50; $i++) { echo $time = time()+$i . "<br />"; // add a day on each iteration echo date('y-m-d', $time) . "<br />"; // should echo 10-12-02, 10-12-03, 10-12-04, etc.. } what am i doing wrong here? arrgggg! maybe its too late for this s$%^#! Similar TutorialsTo solve a bigger issue I'm having in WordPress, I have thrown together this basic script in PHP script to help me get to the bottom of it. Basically, I am trying to add a <hr /> tag after every 3rd paragraph: http://www.mattpealing-server.co.uk/~freshmat/wp-content/themes/match2move/test.php With the following code: <?php $count = 0; ?><?php while($count < 20) : ?><span><p><strong><?php echo $count; ?>:</strong> Lorem ipsum dolor sit amet, consectetuer adipiscing.</p></span><?php if ($count % 3) : ?><hr /><?php endif; ?><?php $count ++; ?><?php endwhile; ?>() However if you notice, this output just doesn't turn out like this! Does the operator I'm using not test if $count is a multiple of 3? So I have a very simple for loop that I am populating a list with levels and exp required to achieve the next level. I have been using a sandbox to test my output and have also created an excel sheet to replicate the data to verify the content. This code was not mine from the beginning and in creating the spreadsheet I discovered the flaw. Below is the code I am trying to fix: function experience($L, $pres = 0) { $a = 0; $end = 0; for ($x = 1; $x < $L; ++$x) { $a += $x * round($x + 5 * pow(4, ($x / 300))); } if ($x > 199) { $a += $x * round($x + 7 * pow(4, ($x / 290))); } if ($x > 399) { $a += $x * round($x + 11 * pow(4, ($x / 280))); } if ($x > 599) { $a += $x * round($x + 19 * pow(4, ($x / 270))); } if ($x > 799) { $a += $x * round($x + 35 * pow(4, ($x / 260))); } if ($x > 999) { $a += $x * round($x + 67 * pow(4, ($x / 250))); } return round($a / 1.25); } Below is the troubleshooting I am attempting to do (Modified and simplified for and while loop): //for loop $no = 200; $a = 0; for ($x = 1; $x < $no; ++$x) { $a += $x + 1; } if ($no > 199) { $a += $x + 2; } echo $a; //while loop $no = 200; $a = 0; $x = 1; while (($x - 1) < $no) { $a += $x * round($x + 5 * pow(4, ($x / 300))); $x++; if ($x > 199) { $a += $x * round($x + 7 * pow(4, ($x / 290))); } } echo $a; Upon request I can also provide snipets of the excel sheet. So the gist of what the issue I am having is this. Between level 199 and 200 the iteration of the loop is running one extra time through the initial formula. As you can tell at level 200, 400, 600, 800 and 1000 I want this formula to change so that it simplifies the amount of exp required to achieve the next level. I can not for the life of me figure out how to restrict the loop while still allowing the values 200 up to run through it for the first 199 iterations. The output I should get from the primary code for levels 199 through 201 are as follows: 199 = 200 = 201 = At level 199 I am good but for whatever reason it runs one additional iteration at the level 1-199 formula and then moves on to the 200 level formula messing up the values. Any and all help is much appreciated. I am a novice hobbyist at best and have been doing this for many, many years now but sometimes I get stumped. I chalk it up to lack of proper training and time to really be serious with it. Thanks in advance....NICON
$start = 0; must be v easy to answer for many here but i dont know how to do it how can i use for loop to print values between any range but with increment of 0.5 0 0.5 1 1.5 2 2.5 3 ........till n Hi, I have coded a lot in the past but only now getting into PHP and web coding in general, when I use a while loop in most other languages I need to increment some form of counter to move to the next item e.g. Code: [Select] while (count < 10) { Do something; count + 1; } I am going through a set of tutorials that have just enlightened me to the following code when looking up a MYsql d'base: Code: [Select] $reults = "SELECT * FROM table"; while ($row = mysql_fetch_assoc($results)){ extract($row); echo $tblcol1; echo " - "; echo $tblcol2; echo "<br>"; } Now in fairness I have no real problem with this, if thats how you extract your results from a query then fine but I feel I am missing something and have not been able to nail it on the head. Am I to assume that $row in the loop returns the first row from the query results, moves through the actions of the loop, returns then automatically points to the next row of the array? Does that mean while($row){} where $row is a 3x3 array(for example) it would loop through this 3 times assigning the next row until the end? Is there a better way to explain this? Hi All, I'm hoping someone can help as I've got myself in a muddle on some code. Basically, the form has a date field (date moved in). If the date entered is over 3 years old, all's ok However, if the date entered is less than 3 years old, the user needs to complete a list field. The list field is essentially a repeater field with a date and address field. If the user adds a date and address and this (plus the original date) is more than 3 years combined history - happy days! If the user adds a date and address and they've still not hit 3 years history, then I need to increase the number of rows (this is handled by another function which works by incrementing a field on the form. As it stands, it works until I need another field to appear i.e. they've entered the first date, then entered a date within the list/repeater field but still not got 3 years worth. I think it's more or less there but seem to have muddled some of the logic (I think/hope!). A fresh pair of eyes would be great: Here's my code: function dateDiffInDays($date1, $date2) { # Calulating the difference in timestamps $diff = strtotime($date2) - strtotime($date1); # 1 day = 24 hours # 24 * 60 * 60 = 86400 seconds return abs(round($diff / 86400)); } add_filter( 'gform_pre_render_2', 'applicant_2_previous_address_history' ); add_filter( 'gform_pre_validation_2', 'applicant_2_previous_address_history' ); function applicant_2_previous_address_history( $form ) { #get the value from the form date input d/m/Y so need to change $get_moved_in_date = rgpost( 'input_1' ); if ( $get_moved_in_date ) { #convert the date format $moved_in_date = date_format(date_create_from_format('d/m/Y', $get_moved_in_date), 'd-m-Y'); #echo "New date format is: ".$moved_in_date. "<br/>"; } #get todays date $today = date("d-m-Y"); #echo "<h3>Today: ".$today."</h3>"; #calculate the difference in days $dateDiff = dateDiffInDays($today, $moved_in_date); #printf("<p>Difference between two dates: " . $dateDiff . " Days</p>"); #check if we moved in less than 3 years ago if ( $dateDiff < 1095 ) { #less than 3 years, so need to loop through the list fields, compare dates and tally totals days if ( $days_sum < 1095 ) { # get the input from the list $list_values = rgpost( 'input_2' ); $i = 0; #use this to get even rows only due to the way data is stored :( $sum = 0; #use this to increment the no. of rows in the list $previous = null; #use this to calc date difference between rows $days_sum = $dateDiff; #set the total number of days. Don't start at 0, start from current date - time at current residence if ( $list_values ) { foreach ( $list_values as $key => $value ){ #get even rows only if($i%2 == 0){ #$sum = $sum + 1; #increment our rows if ( $value ) { #convert the date format $additional_date = date_format(date_create_from_format('d/m/Y', $value), 'd-m-Y'); #echo "<h3>Date: ".$additional_date."</h3>"; } if ( $previous !== null ){ # if it's null, we're in the first loop #convert the date format $previous_date = date_format(date_create_from_format('d/m/Y', $previous), 'd-m-Y'); $dateDiff2 = dateDiffInDays($additional_date, $previous_date); printf("<p>Next Iteration Difference between " . $additional_date . " and " . $previous_date . " is: " . $dateDiff2 . " Days</p>"); $days_sum = $days_sum + $dateDiff2; } else { #convert the date format $dateDiff1 = dateDiffInDays($additional_date, $moved_in_date); printf("<p>1st Iteration Difference between " . $additional_date . " and " . $moved_in_date . " is: " . $dateDiff1 . " Days</p>"); $days_sum = $days_sum + $dateDiff1; } $previous = $value; # set the current value, so it will be saved for the next iteration } $i++; } #end foreach $list_values } #endif $list_values $sum = $sum + 1; #increment our rows echo "<p>Total no of days = " .$days_sum.'</p>'; } #endif $days_sum < 1095 echo '<p>Not enough days so loop through list</p>'; $flag = 'true'; } else { echo '<p>Were ok!</p>'; $flag = 'false'; } #endif $dateDiff < 1095 /* if ( $dateDiff < 1095 ) { $value = 'yes'; } else { $value = 'no'; } */ #we moved in less than 3 years ago, so get history if ( $flag == 'false' ) { return $form; } foreach ( $form['fields'] as &$field ) { if ( $field->id == 2 ) { $field->isRequired = true; } echo "<p>The sum of array element is = " .$sum.'</p>'; if ( $field->id == 3 ) { $_POST['input_3'] = $sum; } } return $form; } Thanks I have only one result being displayed in a select query result whereas I'm expecting 4 results in an array. This is my code below. $sq2="SELECT course FROM course_reg WHERE userid=?"; $stm =$conn->prepare($sq2); $stm->bind_param("s",$logged); $stm->execute (); $return2= $stm->get_result(); $r2 = $return2->fetch_all(); //print_r($r2); foreach($r2 as $course){ foreach($course as $courses){ echo $courses; } }
If I do print_r($r2); it comes out with array containing all the possible results. When i loop through the array to get individual result, it only comes out with a single result. I.e CME211 I would be glad if you can help me figure where the issue is. Thanks!!!
I am trying to load all rows from a table in a database into a table on a webpage. I cannot understand why the following code does not work: Code: [Select] <?php ... echo "You are currently in a fleet. The details of the fleet are below.<br>"; $fleetName = $_SESSION['charFleetName']; $sqlFleetDetails = "SELECT * FROM `$fleetName`"; $queryFleetDetails = mysql_query($sqlFleetDetails); echo "<table>"; echo "<tr>"; echo "<th>Pilot</th>"; echo "<th>Ship</th>"; echo "<th>Type</th>"; echo "</tr>"; while($rowFleetDetails = mysql_fetch_array($queryFleetDetails)) { $charId = $rowFleetDetails['charId']; $charName = $rowFleetDetails['charName']; $shipHull = $rowFleetDetails['shipHull']; $shipType = $rowFleetDetails['shipType']; echo "<tr>"; echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>"; echo "<td>" . $shipHull . "</td>"; if($shipType == 1) echo "<td>Logistics</td>"; if($shipType == 2) echo "<td>DPS Boat</td>"; if($shipType == 3) echo "<td>Sniper 120Km+</td>"; if($shipType == 4) echo "<td>Off-grid Booster</td>"; echo "</tr>"; } echo "</table><br>"; I originally had the $rowFleetDetails['charId'] and others in the echo instead of loading them into variables then echoing the variables but changed it to see if that was working, neither is. If I add an extra line outside of the while loop to echo the output of the array then the information is displayed fine, so I know that the information is being transferred from the table into the array correctly, but why is it not outputting properly in the While loop?
hi, i’m currently facing a new problem (i managed to use array_unique function successfully but i face this problem)with my php loop. i couldn’t seem to increment in my foreach loop to get the value of an array. $update_id1=Array ( [0] => 398 [1] => 397 [2] => 393 [3] => 391 [8] => ); //$i=0; foreach ($update_id1 as $i => $v) { $ex= explode(",", $v); $unique=array_unique($ex); //f$ketch username from update table in db and inject it to the feed query. $imp_id= implode(',', $ids); //$id1=$ids[$i]; // $x=0; // for($x=0;$x<count(unique);$x++){ echo 'ids:- '.$i; print_r($unique[$i]); echo '<br>'; //} $totalUpdates=$project->totalUpdates($ids[$i],$_SESSION['uname'] ,$unique[$i],$load); //$i++; } i tried every method nothing seems to work can anyone help me in this regard please. Edited December 25, 2019 by narutofanHello I want to check that a variable the user enters is not empty and that it is a string (no numbers). Here is what i have written: Code: [Select] <?php include('css/layout.css.php'); include('css/menu.css'); if (isset($_POST['submit'])) { include('includes/dbconn.php'); if (is_string($_POST['name']) && strlen($_POST['name']) > 0) { $name = mysql_real_escape_string($_POST['name']); } else { echo "Category name must be a word!<br />"; } if (isset($name)) { echo $name; } else { echo "something"; } } ?> and this is the form i'm getting the data from: Code: [Select] <form action="category_add.php" method="post"> <table class="table-view"> <tr> <td><label for="name">Category Name</label></td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td><input type="submit" value="Save changes" name="submit" id="submit"></td> </tr> </table> </form> If i enter nothing it works fine, if i enter a string it also works fine, the problem is when i enter 123 in the textbox, i dont get the "Category name must be a word!" as i expected i would. Could someone help me with this one please? Thanks in advance. I'm using PHP 5.2.14 under Windows XP. I'm trying to use ini_set to turn on the 'track_error' configuration option, and it's not working. I make this call, $xxx = ini_set('track_error',"1"); and it returns false. According to the documentation, track_error can be set from any source (including ini_set). What could prevent that from happening? Going back one step, I want to set track_errors so that I can fetch and process the error which occurs when mysql_connect fails. Since it fails, it returns no link, making it impossible to call mysql_errors. Whether ini_set can be made to work or not, is there another, perhaps better way to accomplish this? Hi- I did this and it works... based on the date, the values in the array (from 1 to 9) are echoed by calling $num. Code: [Select] <?php $start = "2012-02-27"; $now = date("Y-m-d"); $week2 = strtotime(date("Y-m-d", strtotime($start)) . " +1 week"); $week2_st = date("Y-m-d", $week2); $week3 = strtotime(date("Y-m-d", strtotime($start)) . " +2 weeks"); $week3_st = date("Y-m-d", $week3); $week4 = strtotime(date("Y-m-d", strtotime($start)) . " +3 weeks"); $week4_st = date("Y-m-d", $week4); $week5 = strtotime(date("Y-m-d", strtotime($start)) . " +4 weeks"); $week5_st = date("Y-m-d", $week5); $week6 = strtotime(date("Y-m-d", strtotime($start)) . " +5 weeks"); $week6_st = date("Y-m-d", $week6); $week7 = strtotime(date("Y-m-d", strtotime($start)) . " +6 weeks"); $week7_st = date("Y-m-d", $week7); $week8 = strtotime(date("Y-m-d", strtotime($start)) . " +7 weeks"); $week8_st = date("Y-m-d", $week8); $week9 = strtotime(date("Y-m-d", strtotime($start)) . " +8 weeks"); $week9_st = date("Y-m-d", $week9); $var_name = array('1', '2','3','4,'5','6','7,'8','9'); if ($now <= $week2_st){ $num = $var_name[0];} elseif($now >= $week2_st && $now <= $week3_st){ $num = $var_name[1];} elseif($now >= $week3_st && $now <= $week4_st){ $num = $var_name[2];} elseif($now >= $week4_st && $now <= $week5_st){ $num = $var_name[3];} elseif($now >= $week5_st && $now <= $week6_st){ $num = $var_name[4];} elseif($now >= $week6_st && $now <= $week7_st){ $num = $var_name[5];} elseif($now >= $week7_st && $now <= $week8_st){ $num = $var_name[6];} elseif($now >= $week8_st && $now <= $week9_st){ $num = $var_name[7];} elseif($now >= $week9_st){ $num = $var_name[8];} else{ $num :'( = $var_name[0];} ?> I'm trying to do a for loop so the index # increments by one and i only call $r instead $var_name[0], $var_name[1], $var_name[2], and so one. Any ideas? Code: [Select] $count = count($var_name); for ($i = 0; $i < $count; $i++) { $r = $var_name[$i]; } I cannot get this INSERT to work. Not records are being added to the sys_city_dev table. No query errors are being thrown. I am simply trying to add ALL records from all_illinois to sys_city_dev and Mid should have be add as 11 in all inserts. city_name of course will be field city_name from all_illinois. Here is my code: $query = "SELECT * FROM all_illinois"; if ($results = mysqli_query($cxn, $query)) { $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($rows = mysqli_fetch_array($results)) { echo $rows['city_name'] . "<br />"; $mid_id = '11'; $insert_city_query = "INSERT INTO sys_city_dev (ID, Mid, cityName, forder, disdplay, cid) VALUES (' ','" . $mid_id . "','" . $rows['city_name'] . "', '', '','')"; if (!$insert_city_query) exit(mysql_error()); } } } Here is my insert table structure and 5 records dump: -- -- Table structure for table `sys_city_dev` -- CREATE TABLE IF NOT EXISTS `sys_city_dev` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev` -- INSERT INTO `sys_city_dev` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'Dothan', 0, 0, 0), (84011, 1, 'Alabaster', 0, 0, 0), (84012, 1, 'Birmingham', 0, 0, 0), (84013, 2, 'Flagstaff', 0, 0, 0), (84014, 1, 'Auburn', 0, 0, 0); And the all_illinois dump w/ 5 records: -- -- Table structure for table `all_illinois` -- CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `all_illinois` -- INSERT INTO `all_illinois` (`state_id`, `city_name`) VALUES ('135', 'Abingdon'), ('135', 'Adair'), ('135', 'Addieville'), ('135', 'Addison'), ('135', 'Adrian'); Hello, Currently have an array like looks like the following when using print_r($session->items): Array ( [F1225] => 1 [EDS11147317] => 1 [1156D6RE001] => 1 [I111ADE47946] => 1 [S679AQ339] => 1 [S67914599] => 1 [CH111337631254] => 1 [S6787903647] => 1 [A11144O189] => 1 [F11144520] => 1 [121584Q12] => 1 [I11144661ADE] => 1 [S678829NB] => 1 ) I am trying to check if an item is in the array and if so, display a different result but currently every item says it is in the array when they are not (unless my logic is off...from the items I am looking at some should be included and some should not..but the below code is showing every item as having the same result). Example: foreach ($items as $item) { if (in_array($item->ItemID, $session->items)) { //$session->items is the array output above echo "In Array"; } else { echo "NOT in Array"; } } Currently everything say "In Array" when some should not. Am I using the in_array incorrectly? Thanks Everyone. Good morning! I've spent hours on this to no avail. My understanding is that unset() only deletes the copy of the variable local to the current scope. But I am getting a very different result. I have the following structure and output. What am I doing wrong? <?php first_function(); second_function() { for ($count = 0; $count < $max; $count++) { $my_array = array[]; //initialize my array, local in this scope but can be called global in nested functions print_r($my_array ); //print 1: array should be always empty but is only in empty in FIRST loop. third_function(); //fills the array with numbers, see below, nested function declaring a global array print_r($my_array ); //print 3 of my_array, should be full of numbers from third_function global changes unset($my_array); //delete my array so I can start with new array in next loop print_r($my_array ); //print 4 of my_array, should be unknown variable print('End one loop'); } } third_function() { global $my_array; //declare my global variable //...fill my now global array with stuff... print_r($my_array ); //print 2: should be filled with numbers. And it is. } ?> My output amazingly looks something like this Array() Array(45,48,38...all my numbers...) Array() ERROR: Notice -- Undefined variable: my_array End one loop Array(45,48,38...all my SAME numbers again as if array was NOT unset...) ...... The first and second print lines make sense. But shouldn't the third line be the array filled with numbers generated in third_function? The fourth line error makes sense as the variable is unset. But WHAT did I unset? The next time around in the loop, the array contains the SAME numbers from the previous loop and my new numbers simply get appended to the end of the ever growing array. Why? This should not be that difficult but seems to be driving me crazy. Any help would be greatly appreciated. alexander Hi Guys Ever had the feeling your being a spoon and can't see the wood for the trees? Well, that's how I feel today. All I am trying to to is implement a variable in a "foreach" loop that increments by one through each iteration of the loop. I know how to do it in a "for" loop but can't for the life of me get it to work here. Here is the code: foreach ($cart as $prodcode => $qty) { $item = get_product_details($prodcode); echo '<input type="hidden" name="item_name_'.[b]$needavariablehere[/b].'" value="'.$item['description'].$_SESSION['finish'][$prodcode].$_SESSION['handles'][$prodcode].'" />' . "\n"; } Where I have highlighted $needavariablehere is where I want a number to appear i.e. if there is one item available and the foreach loop iterates once I want the number 1 here. If there are two items and the foreach loop iterates twice I want the output to have number 1 in the first line and number 2 the second time around and so on. How many times the foreach loop iterates is based on the $cart array which contains items in a shopping cart. Thanks for any help you can give guys. I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. hi I'm coding a page and I was trying to iterate an iteration. but it doesn't seem to work. is this possible in php? Code: [Select] $pageTpl->setIteration('iPlaylist'); // loop all collections and output them foreach ($playlists as $playlist) { // assign collection & urls in template $pageTpl->assignIteration('playlist', $playlist['Title']); $pageTpl->refillIteration(); $pageTpl->setIteration('iMusic'); foreach ($songs as $song){ $pageTpl->assignIteration('path', STREAMING_PREFIX.substr($song['Filename'], 7)); $pageTpl->assignIteration('songId', $song['SongId']); $pageTpl->assignIteration('title', $song['Title']); $pageTpl->assignIteration('artist', $song['Artist']); $pageTpl->assignIteration('time', FYMFunctions::Sec2hms($song['Length'])); $pageTpl->assignIteration('genre', $song['Genre']); $pageTpl->assignIteration('delete', 'removeSong('.$song['SongId'].')'); $pageTpl->refillIteration('iMusic'); } // parseIteration $pageTpl->parseIteration('iMusic'); } // refillIteration $pageTpl->refillIteration(); // parseIteration $pageTpl->parseIteration('iPlaylist'); this is the piece of code... did I do anything wrong? Hello,
Here is my code:
<?php require 'vendor/autoload.php'; $client = new Elasticsearch/Client(); $root = realpath('~/elkdata/for_elk_test_2014_11_24/Agencies'); $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); $paths = array($root); foreach ($iter as $path => $dir) { if ($dir -> isDir()) { $paths[] = $path; } } //Create the index and mappings $mapping['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code $mapping['body'] = array ( 'mappings' => array ( 'documents' => array ( '_source' => array ( 'enabled' => true ), 'properties' => array( 'doc_name' => array( 'type' => 'string', 'analyzer' => 'standard' ), 'description' => array( 'type' => 'string' ) ) ) ) ); $client ->indices()->create($mapping) //Now index the documents for ($i = 0; $i <= count($paths); $i++) { $params ['body'][] = array( 'index' => array( 'type' => 'documents' 'body' => array( 'foo' => 'bar' //Document body goes here ) ) ); //Every 1000 documents stop and send the bulk request. if($1 % 1000) { $responses = $client->bulk($params); // erase the old bulk request $params = array(); // unset the bulk response when you are done to save memory unset($responses); } } ?>I am looking to index a large amount of documents using elastic search and php. I have a very complex directory filled with other directories that i need to index into an array. I wanted to see if my code looked right, and if not what am I doing wrong? Thanks, Austin Harmon |