PHP - Problem Outputting Totals In While Loop
Hi, I'm having issues trying to add up the totals of each product type in a while loop- I'm sure it's straightforward to fix but for some reason I can't find a way to get it to add up all the totals of the various product types and list them so we have say 5 of product 1, 11 of product 2, 8 of product 3 and so on. So firstly the user searches between two different dates / times to get the orders made during that time period: (I'm using separare date and time fields as the datetime-local input doesn't work in a lot of browsers)
if($_POST['search']) //Now get the orders from the db $getorders = $oc_conn->query("SELECT * FROM oc_order WHERE date_added >= '$datetime1' AND date_added <= '$datetime2' AND order_status_id != 0 ORDER BY order_id DESC"); //Then generate start of a table in HTML, the while loop that follows will populate the rows while ($row = $getorders->fetch_assoc()) { //Get the order data
$firstname = $row["firstname"]; [/PHP] As mentioned in the comment above, what I need is the total $quantity of each $productname, across ALL orders in the time range, so that I can see how many of each product ($productname) were ordered in total. I tried using SUM for quantity in the mySQL, and COUNT for adding up the different product names but for some reason it didn't work. Can someone let me know what I need to do? Thanks :)
Similar Tutorialshope to input the below data via $_POST into a while loop to preg_split by comma and then recursively create xml element tag with the various firstName lastName's and even separate further aliasFirstName aliasLastName's into an attribute field NAMES: firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName] $xml .= ' <element1 attribute="' . $_POST('AGE') . '">'; while ($row = ' . $_POST('NAMES') . ') { $row = preg_split('/[\s]*[,][\s]*/',' . $_POST["Actors"] . ',PREG_SPLIT_OFFSET_CAPTURE); $xml .= ' <element2> <NAME names="' . $_POST('NAMES') . '" alias="' . $_POST('NAMES') . '"></NAME> $xml .= ''; 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? Hey Guys. I crearted a class that goes loops through the session cart and displays the items. The problem that I am facing is when a return the values from a method it only brings back the first item that was added to the cart. It doesn't out out all the values.
However when I echo the the values straight from inside the method it shows all the items it looped through. I have tried every possibly thing to have all the items be displayed but I couldn't find to seem a solution.
Please note that I skipped a lot of the code in the example below for breviety. Such as instantiation, and other things. There maybe some syntax errors as well. I just did a breif copy and paste
Any help would be really appreciated!!!
class coreCartFunctions { protected function DisplayMenuItems($menu_item_id_session){ $qty_output = "<span style=\"font-size:18px\">X{$this->item_qty}</span>"; $this->menu_item_name = $this->getItems($this->menu_item_id,"menu_item_name"); if($this->DisplayPrice()){ $update_order_url ="item-detail.php?update_order=true&menu_item_id={$menu_item_id_session} &callback_url={$this->url}&store={$_SESSION['store_name']}"; $output = "<a class='{$this->menu_items_class_prop_a}' href='{$update_order_url}'> <div class='{$this->menu_items_class}'>{$qty_output} {$this->menu_item_name}</div>"; $output .= "<div class='menu_item_price'>\${$this->menu_item_price}</div></a>"; return $output; } else { $output = "<a class='{$this->menu_items_class_prop_a}' href='#'><div class='menu_item_name'>" .$qty_output." ".$this->menu_item_name ."</div></a>"; return $output; } } class displayCartItems extends coreCartFunctions { public function GetMenuItems() { foreach ($this->items as $menu_item_id_session) { //assign all the properties that belong to core class $output = $this->DisplayMenuItems($menu_item_id_session); return $output } } $display_items = $display_menu_item->GetMenuItems(); echo $display_items I have a Q&A Form/script where registered Users can share there thoughts on 10 Questions. On the backend I have these tables: member, answer, question Thanks to some help last night, I have been able to do a LEFT join and store the above data in a multi-dimensional array which always stoes the 10 Questions, and also any Answers that the User may have responded to. (Questions are optional.) I am having a hell of a time DISPLAYING this multi-dimensional array. The key is that I want my PHP and array to stay at the top of my script and use minimal PHP in my HTML section. Here is how I query the data and build my array... // ******************** // Build Q&A Query. * // ******************** // Build query. $q7 = "SELECT q.id, q.question_no, q.question_text, a.answer_text FROM bio_question AS q LEFT JOIN bio_answer AS a ON q.id=a.question_id AND a.member_id =? ORDER BY q.question_no"; // Prepare statement. $stmt7 = mysqli_prepare($dbc, $q7); // Bind variables to query. mysqli_stmt_bind_param($stmt7, 'i', $memberID); // Execute query. mysqli_stmt_execute($stmt7); // Store results. mysqli_stmt_store_result($stmt7); // Check # of Records Returned. if (mysqli_stmt_num_rows($stmt7) > 0){ // Questions Found. // Bind result-set to variable. mysqli_stmt_bind_result($stmt7, $questionID, $questionNo, $questionText, $answerText); // Populate PHP array with Questions & Answers. $x=1; while (mysqli_stmt_fetch($stmt7)){ $thoughtsArray[$x] = array('questionID' => $questionID, 'questionText' => $questionText, 'answerText' => $answerText); $x=$x+1; } echo '<pre>'; print_r($thoughtsArray); echo '</pre>'; // Close prepared statement. mysqli_stmt_close($stmt7); And in my HTML Form, here is how I am attempting to dynamically build the Q&A section... <form id="changeAnswers" action="" method="post"> <fieldset> <legend>Change Profile Answers</legend> <?php echo '<p>TEST: ' . $thoughtsArray[4]['answerText'] . '</p>'; foreach($thoughtsArray as $questionNo => $qaArray) { echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>'; echo '<textarea id="question' . $questionNo . '" name="thoughtsArray[' . $questionNo . '][\'answerText\']" cols="60" rows="2">' . (isset($questionNo]) ? "htmlentities($thoughtsArray[$questionNo]['answerText'], ENT_QUOTES" : '') . '</textarea>'; } ?> I am able to retrieve and display the Questions from my multi-dimensional array as seen above, however, for the life of me, I cannot get the Input Fields (with any Answers) to work properly. I either get compile errors, or the code runs but my Input Fields are blank even when an Answer should be displayed?! I am hoping this is just a syntax and/or reference error. I'm still new to arrays, so properly retrieving an Answer from a multi-dimensional array is really tricky for me!! So close and yet so far away?! Can someone please help me out?? Thanks, Debbie I have a script that runs for quite a while (about 700 second per video). When it is run, it outputs some information for a cURL session. Once the cURL process is initiated php starts downloading a large file to a directory. The file is around 65mb. When the file is finished downloading through curl I have the following code: Code: [Select] echo "Downloaded <br />"; $sw->runDBQuery("UPDATE `videoinfo` SET `videoDownloaded` = '1' WHERE `videoStorageKey`= '".$videostoragekey."' ");The problem I am having is that the script is NOT outputting "Downloaded" in SSH or in the browser BUT the SQL query is being run correctly, and in the background the script moves onto the next file to download (i can see this by monitoring the download directory) but I see no output at all! This leads me to come to two conclusions. Apache is not timing out the request as in SSH, apache is not involved. The browser is not at fault, as I am using Putty. So what could be causing this issue? I am TOTALLY stuck. I cannot work out what the issue could be, it is driving me insance. Any help would be appreciated. ok, so I can't seem to figure out why when I take this code: Code: [Select] <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT SUM(amount) AS total FROM payment where cart_id='$cid'"); while($row = mysql_fetch_array($sql)){ $amount123 = $row["total"]; ?> <?php $left = $total-$amount123; } ?><?php echo $left; ?>I echo $left and instead of subtracting $amount123 from $total, it subtracts it from zero, but when I refresh the page, it works properly. can anyone see what the issue is? Ok, I am running a baseball site and we have our player stats all in a table within a database. What I have is something like this, http://www.stlbleague.com/tm.php?tid=7... Now what I would like to do is have a row at the end of the pitching and hitting stats that says "Team Totals", here is a sample code that I have pulling the pitching stats: Code: [Select] $id = $_GET['tid']; // get var from URL /* Get data. */ $sql = "SELECT player, pos, era, w, l, sv, hold, ip, bb, k, cg, sho, whip, k9 FROM 2012pitching LEFT JOIN roster ON 2012pitching.id=roster.id WHERE tid='$id'"; $result = mysql_query($sql); ?> <table width="962" border="0" cellpadding="2" cellspacing="1" class="stats2"> <tr class='theader'> <td align='center'>PLAYER</td> <td align='center'>POS</td> <td align='center'>ERA</td> <td align='center'>W</td> <td align='center'>L</td> <td align='center'>SV</td> <td align='center'>HOLD</td> <td align='center'>IP</td> <td align='center'>BB</td> <td align='center'>K</td> <td align='center'>CG</td> <td align='center'>SHO</td> <td align='center'>WHIP</td> <td align='center'>K/9</td> </tr> <?php $alternate = "2"; while ($row = mysql_fetch_array($result)) { $field1 = $row["player"]; $field2 = $row["pos"]; $field3 = $row["era"]; $field4 = $row["w"]; $field5 = $row["l"]; $field6 = $row["sv"]; $field7 = $row["hold"]; $field8 = $row["ip"]; $field9 = $row["bb"]; $field10 = $row["k"]; $field11 = $row["cg"]; $field12 = $row["sho"]; $field13 = $row["whip"]; $field14 = $row["k9"]; if ($alternate == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#E4E4E4"; $alternate = "1"; } echo "<tr bgcolor=$color><td>$field1</td><td align='center'>$field2</td><td align='center'>$field3</td><td align='center'>$field4</td><td align='center'>$field5</td><td align='center'>$field6</td><td align='center'>$field7</td><td align='center'>$field8</td><td align='center'>$field9</td><td align='center'>$field10</td><td align='center'>$field11</td><td align='center'>$field12</td><td align='center'>$field13</td><td align='center'>$field14</td></tr>"; } echo "</table>"; ?> So how could I use the Team ID associated with every player that it is pulling from to add a totals row? Thanks again in advance, Bobby Currently we have a Microsoft Access database which we use to display a report, we are rolling over to PHP/SQL online for greater control e.t.c. So far we have the report pulling all the information from the database however we need to group this information by Day followed by Employee, sorted by time and then totaled for each Employee for each day. Below is the code we have so far which only prints columns how do we go about displaying it like the access screenshot. Attached is an example of the Microsoft Access report we have. Code: [Select] <?php $username='admin'; $password='password'; $database='planner'; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM reservations ORDER BY start_date, machid, starttime"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <?php $i=0; while ($i < $num) { $f0=mysql_result($result,$i,"machid"); $f1=mysql_result($result,$i,"start_date"); $f2=mysql_result($result,$i,"end_date"); $f3=mysql_result($result,$i,"starttime"); $f4=mysql_result($result,$i,"endtime"); $f5=mysql_result($result,$i,"first_name"); $f6=mysql_result($result,$i,"last_name"); $f7=mysql_result($result,$i,"company"); $f8=mysql_result($result,$i,"phone_number"); $f9=mysql_result($result,$i,"site_address"); $f10=mysql_result($result,$i,"site_suburb"); $f11=mysql_result($result,$i,"site_postcode"); $f12=mysql_result($result,$i,"postal_address"); $f13=mysql_result($result,$i,"postal_suburb"); $f14=mysql_result($result,$i,"postal_postcode"); $f15=mysql_result($result,$i,"job_type"); $f16=mysql_result($result,$i,"payment_type"); $f17=mysql_result($result,$i,"payment_status"); $f18=mysql_result($result,$i,"quote_outcome"); $f19=mysql_result($result,$i,"quote_amount"); $f20=mysql_result($result,$i,"quote_employee"); $f21=mysql_result($result,$i,"job_income"); $f22=mysql_result($result,$i,"job_materials"); $f23=mysql_result($result,$i,"invoice_number"); $f24=mysql_result($result,$i,"job_notes"); /* START TIME */ $stime = $f3; $shour = floor($stime/60); $smin = str_pad($stime % 60,2,0,STR_PAD_LEFT); //echo $hour.':'.$min; //echo '<br><br>'; // For AM/PM $shalf = 'am'; if( $shour > 12 ) { $shalf = 'pm'; $shour -= 12; } $stime = $shour.':'.$smin.' '.$shalf; /* END TIME */ $etime = $f4; $ehour = floor($etime/60); $emin = str_pad($etime % 60,2,0,STR_PAD_LEFT); //echo $hour.':'.$min; //echo '<br><br>'; // For AM/PM $ehalf = 'am'; if( $ehour > 12 ) { $ehalf = 'pm'; $ehour -= 12; } $etime = $ehour.':'.$emin.' '.$ehalf; ?> <table width="3500px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="125px"><?php echo $f0; ?></td> <td width="80px"><?php echo date('d-m-y', "$f1"); ?></td> <td width="50px" style="text-align:right;"><?php echo $stime; ?></td> <td width="50px" style="text-align:right; padding-right:20px;"><?php echo $etime; ?></td> <td width="100px"><?php echo $f5; ?></td> <td width="100px"><?php echo $f6; ?></td> <td width="100px"><?php echo $f7; ?></td> <td width="100px"><?php echo $f8; ?></td> <td width="100px"><?php echo $f9; ?></td> <td width="100px"><?php echo $f10; ?></td> <td width="100px"><?php echo $f11; ?></td> <td width="100px"><?php echo $f12; ?></td> <td width="100px"><?php echo $f13; ?></td> <td width="100px"><?php echo $f14; ?></td> <td width="100px"><?php echo $f15; ?></td> <td width="100px"><?php echo $f16; ?></td> <td width="100px"><?php echo $f17; ?></td> <td width="100px"><?php echo $f18; ?></td> <td width="100px"><?php echo $f19; ?></td> <td width="100px"><?php echo $f20; ?></td> <td width="100px"><?php echo $f21; ?></td> <td width="100px"><?php echo $f22; ?></td> <td width="100px"><?php echo $f23; ?></td> <td width="100px"><?php echo $f24; ?></td> <?php $i++; } ?> Once again thanks everyone at phpfreaks! I have a pipe delimited file with this sample content: INV8004199|01/26/2012|Next door|648.00 SPT803487|01/25/2012|This and That|3360.00 INV8004193|01/25/2012|Where is it|756.00 INV8004133|01/05/2012|snowy winter|6750.00 I open the file to read it: Code: [Select] $CPfile = "sample.DEL"; $ft = fopen( $CPfile, "r"); $content1 = fread($ft, filesize($CPfile)); fclose($ft); Then I loop thru it: Code: [Select] $out = explode("\n", $content1); $total = 0; foreach($out as $var) { $tmp = explode("|", $var); for($i=0;$i<count($tmp);$i++){ echo $tmp[$i] . "<BR>"; } } What I would like to get is the total of all prices (last column) in all lines of the file. Can someone help please?. Thanks! Ok, so I have a bit of code but it's not working as it should, would one of you guys have a look at it and let me know where I'm going wrong? Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like: hello: 23,000.000 hello world: 19,000,000 world: 278,000,000 I also see that the script is not searching the words / terms inside quotes (EG. "hello world") TIA Code: [Select] <html> <body> <?php function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $result = curl_exec ($ch); curl_close ($ch); return $result; } $s = $_GET['s']; if (isset($s)) { echo "<p><i>Search for $s</i></p>"; $s = urlencode($s); $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search"); $data = strip_tags($data); $find = 'Results 1 - 10 of about '; $find2 = ' for'; $data = strstr($data, $find); $pos = strpos($data, $find2); $search_number=substr($data,strlen($find), $pos-strlen($find)); echo "Total Results: $search_number"; } else { ?> <form name="form1" id="form1" method="get" action=""> <div align="left"> <p> <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br /> <input type="submit" name="Submit" value="Results" /></p> Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br /> </div> </form> <p> <?php } ?> </p> </body> </html> A WHILE loop in a FOR loop problem Script about links and sublinks from 1 table. In fact 2 questions about that. 1) In the FOR loop I have for example to do the loop 3 times. (needs to find 3 results withing the loop with if and else) When first time, he's gonna search within the WHILE loop that holds (for example) 10 records of the DB in a variable. He needs to search for rowid number 5, he found it He goes out of the WHILE loop and goes searching again but now for rowid number 2 Now it seem that the WHILE loop start searching for number 2 but won't start from his first row in the variable (10 rows from the db ). He start at row number 6 instead of beginning all over again !!! -> so the order of the numbers of rows MUST be in an ascending order, ortherwise he won't find them all ! But the numbers I have are NOT in an ascending order !!! Why doesn't the WHILE loop begin again from his row 1 in the variable ? FOR loop { WHILE loop { content here, break; } } 2) even when I get all the result in an ascending order, he won't go doing a second search but with a different rowid number that he gets from the FOR loop. It is giving me back indeed the right new rowid number, but the WHILE loop is doing nothing. I have put many echo "..."; and other stuff for checking but can't find the cause ! Here's the code : Code: [Select] // $ResultShow = 10 rows from mysql db if(isset($ResultShow)){ if (mysql_num_rows($ResultShow) >= 1){ //$linksuborder = "2,3,4"; $array1 = explode(",", $linksuborder); sort($array1); for ($n = 0; $n < count($array1); $n++){ // searchin for the right row id in the variable $ResultShow where we find the numbers for next loop $r1 = each($array1); While($Row2 = mysql_fetch_array($ResultShow)) { if($Row2["linkid"] == $r1['value']) // found it, now look for the numbers that we'll put in an array { echo "---here the content---"; // linksuborder is where numbers from row id's are stored like 5,2,8 //now put them in an array $array2 = explode(",", $Row2["linksuborder"]); sort($array2); for ($n2 = 0; $n2 < count($array2); $n2++){ $r2 = each($array2); ////// here searching for the sublinks ////// While ($Row3 = mysql_fetch_array($ResultShow)) { if($Row3["linkid"] == $r2['value']) // search for the right row id within the variable $ResultShow { echo "---here the content---"; break; // found it, so no need to do the rest of the loop } // end if } //end while ////// end searching for sublinks ////// } // end for } // end if else { echo "--- content here ---"; } } // end while } // end for } //end if } // end if Table : linkid linksuborder linktitle 1 2,3,4 2 9,7,8 mainlink1 3 10 mainlink2 4 mainlink3 5 6 7 sublink3 8 sublink2 9 sublink1 10 sublink4 -> linksuborder 2,3,4 are the row id's for the mainlink -> than we put the numbers 9,8,7 (also row id's) mentioned in row linkid 2 also in a new array -> now we can search for the sublinks -> get the details from row linkid 9, than 7, than 8 -> First mainlink is compleet, now go to row linkid 3 to do it all over again for the next mainlink... RESULTS from an sorted array -> sort($linksuborder); ------------------------------------------------------------- mainlink1 : sublink1, sublink2, sublink3 mainlink2 : **no result back but it should * mainlink 3 : **no result back but it should * Hi Guys, I am trying update some array values in my database. For some reason using the code below the $checked and $counter values are not working. I have added the echos for debugging purposes and nothing is being echoed. $query = mysql_query("SELECT * FROM offers WHERE seller='$username' AND buyer='$buyer'"); while ($row = mysql_fetch_assoc($query)) { $checked = $_POST['checkbox'][$y]; $counter = $_POST['counter'][$y]; echo $checked; echo $counter; $date = date("Y-m-d"); $time = date("H:i:s"); mysql_query("UPDATE offers SET offer='$counter',seller_status='Counter Offer Made',buyer_status='Counter Offer Received',date='$date',time='$time',seller_action='0',buyer_action='1' WHERE domain='$checked'"); } When i do the following it echos the $checked and $counter values perfectly so i know that the form is posting ok. foreach ($_POST['checkbox'] as $checked) { echo $checked; } foreach ($_POST['counter'] as $counter) { echo $counter; } Can anybody figure out what is wrong with my while loop? Iv been at it for ages and cant seem to crack it. Thanks All,
I am taking the output for every title in my Database and displaying it in a box. Within that box I am providing the opportunity to open another box with further content inside. The problem with the code below is that when you click on the expand button it expands in all the boxes, not just the one you are clicking in. I don't understand why this is happening when everything else is ok - any fixes and explanations are greatly appreciated:
// GOING THROUGH THE DATA if($result->num_rows > 0) { //echo "<hr />"; while($fetch=mysqli_fetch_array($result)) { $title=$fetch['title']; $feed_rss=$fetch['url']; $content_id=$fetch['content_id']; $source_image=$fetch['source_image']; $item_id = $fetch['item_id']; $item_title = $fetch['item_title']; $item_date = $fetch['fetch_date']; $item_description = $fetch['item_description']; $item_url = $fetch['item_url']; ///////////////////////////////////////////////////////////////////////////////// // ?> <div class="box col5"> <?php $query_string = "cid={$content_id}&t={$item_id}&item_title={$item_title}"; $url_query_string = "http://www.disciply.com/article/index.php?" . $query_string; /*Start of dynamic content open*/ echo "<p>$title</p>"; echo "<img src=$source_image />"; echo "<p>item_url = $item_url</p>"; ?> <div class="panel_button" style="display: visible;"><img src="../images/expand.png" alt="expand"/> <a href="#"><?php echo $item_title; ?></a></div> <div class="panel_button" id="hide_button" style="display: none;"><img src="../images/collapse.png" alt="collapse" /> <a href="#">Hide</a> <object type="text/html" data='<?php echo $item_url;?>' width="100%" height="800px" style="overflow:auto;border:5px ridge blue"> </object> </div> </div> Edited by genista, 19 July 2014 - 10:33 PM. hi The output of this code is: 1950 1951 1952 .... script Code: [Select] <?php for ($i = 1950; $i < 2012; $i++) { echo "<option value='$i' class='dr'>".$i.'</option>'; } ?> but i need something like: Insert a date 1950 1951 1952 .... how can i solve that? welll. i can do <option value='null' class='dr'> year</option> Hi! I have a code that don't do want I want that to do. <?php $chars = str_split('abc'); $char_len = count($chars); $length = 3; //loop for char_len^length $loop_length = pow($char_len, $length); for($i = 0; $i < $loop_length; $i++) { //convert $a to chars $string = ''; while($a != 0) { $string = $chars[$a % $char_len] . $string; $a = (int) ($a / $char_len); } //pad and print string echo str_pad($string, $length, $chars[0], STR_PAD_LEFT), "<br>\n"; if($loop_length-1 == $i){ $length++; } } ?> And what it do, is to print out all combination of a, b and c. My problem is that when the loop is done (you'll se my if statement) I want to add one on length so it print out a, b and c in four letters. ex abca, abcb. But it isen't working. Have you any clue that can help me? Thank you for your answer. Hello People. I have a site that I am trying to paste multiple pins on a single map in a wordpress site, using cbxgooglemap plugin and advanced custom fields for my lat and long information. The following code works fine for one pin, on one map. echo do_shortcode('[cbxgooglemap lat="'.get_field('latitude').'" lng="'.get_field('longitude').'" ]'); However, when I try to post it within the loop, I simply get multiple maps, instead of one map, with multiple pins. Here is the code that doesn't work correctly, it gives me 3 maps. <?php $justMap = new WP_Query(array( 'posts_per_page'=> 3, 'post_type' => 'airfield_card' )); while($justMap->have_posts()){ $justMap->the_post(); echo do_shortcode('[cbxgooglemap lat="'.get_field('latitude').'" lng="'.get_field('longitude').'" ]'); } ?> Please can someone tell me how to alter the code so that a single map is outside the loop, but still embedding each pin from the loop.
Kind Regards this foreach loop is causing mysql_num_rows to not return the amount of rows in mysql correctly. the variable $value has two strings in it (testa and testb). So foreach should loop once with $value as 'testa', then loop again with $value as 'testb'. the problem is at the mysql_num_rows. It should return 1 because there is 1 row in mysql with keywords 'testa' and 1 row with keywords 'testb', instead it returns zero. If i change $value to 'testa' it works. Code: [Select] foreach($value as $value) { $updatestable = mysql_query("SELECT * FROM `Stacks` WHERE keywords LIKE '%$value%' ORDER BY id DESC LIMIT 1")or die (mysql_error()); $upnum = mysql_num_rows($updatestable); echo $upnum; if ($upnum==0){ $uporigin=0; } else { while($rowup = mysql_fetch_assoc($updatestable)) { $uporigin = $rowup['origin']; $upreply = $rowup['reply']; } } } hope the question isn't too complicated. basically if i remove the loop. the mysql num_rows works and returns a row. If i don't remove the loop it returns zero. Hello, I have a loop below but the first time the person isn't counted in the if loop... I'm new to php and I know there is something easy I'm missing but I can't see it! Any help you be great. Code: [Select] // loop from mysql reults while($row = mysql_fetch_array( $result )) { echo "Person: ".$row['id']; echo "Earned: ".$row['earned']; //set-up php var's $earnedSum = $row['earned']; $firstPerson = $row['id']; if ($lastPerson == $firstPerson){ $earnedTotal = $earnedTotal + $earnedSum ; // Add's the earn units $lastPerson = $firstPerson; }else{ $earnedTotal = 0 ; // reset $lastPerson = $firstPerson; } echo 'This is the total Earned Result = '.$earnedTotal.'<br>'; } ?> I am trying to loop through a filtered table. This is the code of the loop:
$result = mysqli_query($con,$sql);
$query = "INSERT INTO invoiceitems(invnumber,itemnum,price,quantity) VALUES('$ttinvno','$itemno','$price','$qty')";#,unix_timestamp())";
if ($prebidder != $buser) { } ?> The filtered data has 55 rows of which 28 are unique. I am trying to loop through so that the names ($buser) match the invoice number ($ttinvno). I have the rows indexed on buser descending. But the rows don't seem to want to match correctly. The invoice numbers go in sequence correctly but for instance the first two rows have the same name. But no matter what I have done in this format either the invoice number changes after the first row, or it changes after the third row. I want it to change after the second row. I have tried multiple ways including prematurely defining row and then using mysqli_data_seek($result,0); to reset the result before the loop. Obviously there is a flaw in my code. Can anyone help? Thanks very much in advance!
Why does this code only display 1 result? If I PRINT $row3 all results diplay, but the variable will only give 1 result. It would be easier for me to just PRINT row3, but I have 13 rows with different loops. Code: [Select] $sql = "SELECT * FROM $city WHERE SG_Name='$sg GROUP BY ID'"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) { $ID="{$row[3]}"; } "<tr border='1'> <td>".$Source_ID."</td> </tr>"; |