PHP - Array Of Discounts To Be Applied Based On The Weeks Booked All At Different Rate
Similar Tutorials/* Output of the table will display the Suite based on the distinct date. The pass rate percentage calculate based on the Suite1 and app1 and the specific date. For example at Apr 4 2011, I need to Sum the total passcount,failcount,errorcount of Bluetooth, GPSA, EMIReceiver($app1) of XA9 on Real MXE($suite1) , then calculate the passrate percentages. But I fail to get the correct value of the passcount, failcount, errorcount value.Helps! Output of the table suite Date Percentages(pass rate) XA9 on Real MXE Apr 4 2011 9:47AM 99.94% XA9 on Real MXE Apr 5 2011 10:48AM 99.94% XA9 on Real MXE Apr 6 2011 9:49AM 99.95% XA9.5 on Real EXA_B40 Apr 4 2011 7:06AM 99.94% XA9.5 on Real EXA_B40 Apr 5 2011 7:14AM 99.93% XA9.5 on Real EXA_B40 Apr 6 2011 7:29AM 99.93% */ $suite1 --> array value (XA9 on Real MXE, XA9.5 on Real EXA_B40) $app1 --> array value (Bluetooth, GPSA, EMIReceiver) if(is_array($suite_type1)){ foreach($suite_type1 as $suite1) { $sql222="Select Distinct a.StopDTTM from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$fromdate' and a.StopDTTM<='$to_date' and a.SuiteFilePath like '%$Program%' and a.SuiteFileName='$suite1'"; $result222=mssql_query($sql222,$connection) or die("Failed Query of".$sql222); while($row222 = mssql_fetch_array($result222)) { $datetotest = $row222[0]; $days_to_add = 1; $tilldate = fnc_date_calc($datetotest,$days_to_add); //Query the result based on the date $sql223="Select Distinct a.SuiteFileName, a.SuiteID,a.StopDTTM from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$row222[0]' and a.StopDTTM<='$tilldate' and a.SuiteFilePath like'%$Program%' and a.SuiteFileName='$suite1' order by a.StopDTTM"; $result223=mssql_query($sql223,$connection) or die("Failed Query of".$sql223); while($row223 = mssql_fetch_row($result223)){ foreach($app_type1 as $app1) { $sql3="Select Sum(b.passcount),Sum(b.failcount),Sum(b.errorcount) from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$row222[0]' and a.StopDTTM<='$tilldate' and a.SuiteFilePath like '%$program%' and a.SuiteFileName = '$suite1' and b.Product='$app1'"; $result3=mssql_query($sql3,$connection) or die("Failed Query of ". $sql3); $row3 = mssql_fetch_row($result3); $total_passcount+=$row3[0]; $total_failcount+=$row3[1]; $total_errorcount+=$row3[2]; } $overall_total=$total_passcount+$total_failcount+$total_errorcount; echo "<tr>"; echo "<td><a href='detailsreport.php?suiteID=".$row223[1]."&suitetype=".$row223[0]."&fromdate=".$fromdate."&to_date=".$to_date."&date=".$row222[0]."&tilldate=".$tilldate."&SuiteFilePath=".$Fprogram."'>" . $row223[0] . "</a></td>"; //Suite File Name echo "<td>" . $row223[2] . "</td>"; //Pass percentage if($total_passcount>0){ echo "<td bgcolor=00FF33>" . number_format((($total_passcount/$overall_total)*100),2)."%</td>"; } else{ echo "<td bgcolor=00FF33>0%</td>"; } } } } echo "</table>"; } Hi My website is a Wordpress WooCommerce. I modified the PHP function that worked well before I added the multiple customer roles. I have regular customers and regular and tier-level wholesalers. I live in Canada and with have two taxes to apply (GST & PST). We also have customers/wholesalers that get exempted from one tax (PST) only or both taxes. I have one regular wholesale role with two tax exemption roles: 'wholesale_customer', 'wholesale_pst_exempt', 'wholesale_tax_exempt'. I have 4 tier levels wholesale roles with each their own tax exemption roles: 'wholesale_silvia_silver', 'wholesale_silvia_gold', 'wholesale_silvia_premium', 'wholesale_silvia_union' 'wholesale_silvia_silver_pst_exempt', 'wholesale_silvia_gold_pst_exempt', 'wholesale_silvia_premium_pst_exempt', 'wholesale_silvia_union_pst_exempt' 'wholesale_silvia_silver_tax_exempt', 'wholesale_silvia_gold_tax_exempt', 'wholesale_silvia_premium_tax_exempt', 'wholesale_silvia_union_tax_exempt' The tier levels are new and I'm trying to update my existing function that applies different tax rates based on customer user roles. I also have filters to alter the shipping tax for the different tax class based on the customer role. Here are the function and filter that I have updated to add the additional tier level wholesale roles. The changes I've made are not working because I don't see the tax exemptions. Both taxes are always being applied. Can someone help me figure out what I've done wrong to the code that stopped it from working? I'm not proficient in PHP, so was trying my best to make this work. /* * APPLY DIFFERENT TAX RATE BASED ON CUSTOMER USER ROLE * (Code compacted in one unique hook instead of 5 functions with the same hook) */ function all_custom_tax_classes( $tax_class, $product ) { global $current_user; // Getting the current user $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // 1 customer_tax_exempt /* special tax rate: zero if role: Customer Tax Exempt */ /*if ( in_array( 'customer_tax_exempt', $curr_user_data->roles ) ) $tax_class = 'CustomerTaxExemptClass'; // 2 customer_pst_exempt // special tax rate: charge only GST if role: Customer PST Exempt if ( in_array( 'customer_pst_exempt', $curr_user_data->roles ) ) $tax_class = 'CustomerPSTExemptClass'; */ // 3, 4 & 5 WHOLESLE SUITE SPECIAL WHOLESALE TAX RATES if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // special tax rate: charge both PST and GST if roles: Wholesale Customer, Wholesale Silvia Silver, Wholesale Silvia Gold, Wholesale Silvia Premium, Wholesale Silvia Union if (!empty($wwp_wholesale_role) && in_array('wholesale_customer', $wwp_wholesale_role) && in_array('wholesale_silvia_silver', $wwp_wholesale_role) && in_array('wholesale_silvia_gold', $wwp_wholesale_role) && in_array('wholesale_silvia_premimum', $wwp_wholesale_role) && in_array('wholesale_silvia_union', $wwp_wholesale_role)) { // Where 'wholesale_customer, wholesale_silvia_silver, wholesale_silvia_gold, wholesale_silvia_premium, wholesale_silvia_union' are the names of the wholesale roles to target $tax_class = 'WholesalePSTGST'; } // special tax rate: charge only GST if roles: Wholesale PST Exempt, Wholesale Silvia Silver PST Exempt, Wholesale Silvia Gold PST Exempt, Wholesale Silvia Premium PST Exempt, Wholesale Silvia Union PST Exempt if (!empty($wwp_wholesale_role) && in_array('wholesale_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_silver_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_gold_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_premium_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_union_pst_exempt', $wwp_wholesale_role)) { // Where 'wholesale_pst_exempt, wholesale_silvia_silver_pst_exempt, wholesale_silvia_gold_pst_exempt, wholesale_silvia_premium_pst_exempt, wholesale_silvia_union_pst_exempt' are the names of the wholesale roles to target $tax_class = 'WholesalePSTExempt'; } // special tax rate: zero if roles: Wholesale Tax Exempt, Wholesale Silvia Silver Tax Exempt, Wholesale Silvia Gold Tax Exempt, Wholesale Silvia Premium Tax Exempt, Wholesale Silvia Union Tax Exempt if (!empty($wwp_wholesale_role) && in_array('wholesale_tax_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_silver_tax_exempt', $wwp_wholesale_role)&& in_array('wholesale_silvia_gold_tax_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_premium_tax_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_union_tax_exempt', $wwp_wholesale_role)) { // Where 'wholesale_tax_exempt, wholesale_silvia_silver_tax_exempt, wholesale_silvia_gold_tax_exempt, wholesale_silvia_premium_tax_exempt, wholesale_silvia_union_tax_exempt' are the names of the wholesale role to target $tax_class = 'WholesaleZeroTax'; } } return $tax_class; } /* ADDITIONAL FILTERS TO ALTER THE SHIPPING TAX FOR DIFFERENT TAX CLASSES BASED ON CUSTOMER USER ROLE */ add_filter( 'woocommerce_product_get_tax_class', 'all_custom_tax_classes', 1, 2 ); add_filter( 'woocommerce_product_variation_get_tax_class', 'all_custom_tax_classes', 1, 2 ); add_filter( 'option_woocommerce_shipping_tax_class' , function( $option_value ) { global $wc_wholesale_prices; if ( $wc_wholesale_prices && is_a( $wc_wholesale_prices , 'WooCommerceWholeSalePrices' ) ) { $current_user_wholesale_roles = $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole(); if ( in_array( 'wholesale_customer', $current_user_wholesale_roles ) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_silver', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_gold', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_premium', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_union', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_silver_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_gold_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_premium_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_union_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_silver_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_gold_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_premium_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_union_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } } return $option_value; } , 10 , 1 );
Thank you Lyse Edited June 18, 2019 by LyseSpecify website platforms Hi all,
I am building a random prize assigner function based on weighted percentages.
I am able to assign a basic true/false weighting but am struggling to form a way of selecting an array based prize based on the win rate.
Heres my current code:
function selectPrize() { $prizes = array( 0 => array( 'name' => 'Top Prize', 'rate' => 50 ), 1 => array( 'name' => 'Middle Prize', 'rate' => 30 ), 2 => array( 'name' => 'Bottom Prize', 'rate' => 20 ), ); // oops } selectPrize();Could somebody please give me pointers on how i could approach this? Thanks. Edited by biggieuk, 19 June 2014 - 05:14 AM. Here is my code: <?php //input will be start date $startdate=0; function getMondays($day,$month,$year,$i,$end){ $x = 7; $add=0; for($i; $i<$end; $i++){ $add++; //This will get the first set of Mondays //store it inside an array //time stamp 11 pm GMT on date $array[$i] = date('U', mktime(0, 0, 0, $month, $day+$counter, $year)); //$firstDay = date('d/m/y', mktime(0, 0, 0, $month, 4+$counter, $year)); $counter = $x * $add; } return $array; } This gets the four weeks following the date set and store it in an array: $Weeks = getMondays(04,04,2011,0,5); Each slot is the equivalent of a week e.g. week 1, week 2, week 3, week 4,week 5 //perform equivilence test if($week1==$currentdate || $currentdate<=$week2){ //for all week 1 stick the following sentence echo "data for week 1"; } if($currentdate>$week2 && $currentdate<=$week3){ //for all week 2 stick the following sentence echo "data for week 2"; } if($currentdate>$week3 && $currentdate<=$week4){ //for all week 3 stick the following sentence echo "data for week 3"; } if($currentdate>$week4 && $currentdate<=$week5){ //for all week 4 stick the following sentence echo "data for week 3"; } if($currentdate==$week5){ //where d/m/y = the date on week 5. //will now become week 1 data getMondays(d,m,y,0,4); } Now depending on which week it is, a set data is displayed which is hardcoded. Now what I want to do is to reset the array on week 4 (for the new month), without the array being repopulated with the old date: $Weeks = getMondays(04,04,2011,0,4); everytime the script is run. How do I do this?
Hello, Hi, What i want is relatively simple yet i seem to be massively over complicating it. I've never really had to use forums for help before but this is annoying me now lol. Basically, what i want is when someone orders 3 or more products that aren't in this case, a canvas, they get 20% off the cheapest 3 products. But where things get complicated is that there is also a quantity field. So if someone orders say 1 item at 1.99 and then 3 at 2.99 id have to be able to get 1.99 + 2 lots of 2.99 and then work out the 20% on that. And obviously i dont know what they're going to order so it needs to be something dynamic and i've kinda written rules for several possibilities but i cant get it right. Heres my code so far anyway: $row3 = mysql_fetch_array(mysql_query("SELECT SUM(qty) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 3")); $price3 = mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 3")); $row2 = mysql_fetch_array(mysql_query("SELECT SUM(qty) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 2")); $price2 = mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 2")); $row1 = mysql_fetch_array(mysql_query("SELECT SUM(qty) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 1")); $price1 = mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas' ORDER BY `price` ASC LIMIT 1")); $totalqty3 = $row3['SUM(qty)']; $totalnonec=mysql_num_rows(mysql_query("SELECT * FROM `ypc_cart` WHERE `sessid`='$sessid' AND `type`!='canvas'")); /////IF QTY FROM 3 ITEMS IS MORE THAN 3 OR IS 3 if($totalqty3 > 3 && $totalnonec == 3){ echo "3 > 3"; }elseif($totalqty3 == 3 && $totalnonec == 3){ $otherdiscount = (($price3['SUM(price)'] + 0.03) * 3) * 0.2; /////IF QTY FROM 2 ITEMS IS MORE THAN 3 OR IS 3 }elseif($row2['SUM(qty)'] > 3 && $totalnonec == 2){ $otherdiscount = (($price2['SUM(price)'] + 0.03) * 3) * 0.2; }elseif($row2['SUM(qty)'] == 3 && $totalnonec == 2){ $otherdiscount = (($price2['SUM(price)'] + 0.03) * 3) * 0.2; /////IF QTY FROM 1 ITEM IS 3 OR LESS }elseif($row1['SUM(qty)'] > 2 && $totalnonec == 1){ $otherdiscount = (($price1['SUM(price)'] + 0.03) * 3) * 0.2; }else{ $otherdiscount = 0.00; } $totaldiscount = $otherdiscount; $otherdiscount = (($price3['SUM(price)'] + 0.03) * 3) * 0.2; This is basically, get the price total, add 3p (as all prices end in .99 so it rounds it off) x 3(as you get 20% off 3 items) then x 0.2 to get the 20% value. Probably worth starting over but id have know idea where to begin lol so any help with getting this code to work or posting some new code on where to start would be brilliant! Thanks in advance. I'm looking for a method that will return the date for the next 2 weeks in php. I can pull the date but I'm not sure about adding to the date. Can anyone point me in the correct direction? So I'm calling in data from a DB where each record is associated with a (column) 'start_time', 'no_shows', 'cancelled', and 'attended' I want to go through the results of this SELECT and count the number of no shows, cancellations and attended on a WEEKLY basis (based on the start_time). How can I achieve this?
The user will provide a date range and the DB will select the records based on that date range. Now this date range will then have to be split by weeks and then get the count. I'm totally stuck on the counting by weeks part. This is what I have so far: // Multidimensional Array with [boolean][week #] $no_shows_weekly = [ 'no_show' => [], 'week' => [] ]; $cancelled_weekly = [ 'cancelled' => [], 'week' => [] ]; $attended_weekly = [ 'attended' => [], 'week' => [] ]; foreach($result as $r) { $start_time = new DateTime($r['start_time']); if($r['is_no_show'] == 0 && $r['is_cancelled'] == 0) { array_push($attended_weekly['attended'], 1); array_push($attended_weekly['week'], date_format($start_time, "W")); } else { array_push($attended_weekly['attended'], 0); array_push($attended_weekly['week'], date_format($start_time, "W")); } array_push($no_shows_weekly['no_show'], $r['is_no_show']); array_push($no_shows_weekly['week'], date_format($start_time, "W")); array_push($cancelled_weekly['cancelled'], $r['is_cancelled']); array_push($cancelled_weekly['week'], date_format($start_time, "W")); } echo json_encode(array( 'success'=> 1, 'msg'=> array( 'No Shows' => $no_shows_weekly, 'Cancellations' => $cancelled_weekly, 'Attendend' => $attended_weekly ) )); Any suggestions or help is greatly appreciated! I have the following code: Code: [Select] //DETERMINES ASL POLICY if ($perfRow['ASL']=='ToArrange'){ $ASLdate = $perfRow['startDateTime']; $ASLconfirm = strtotime($ASLdate-'21 days'); echo "<!--[ASL=ToARRANGE--><p>An ASL Interpreted performance of this event is offered on".date("l, F j",strtotime($perfRow['startDateTime']))." at ".date("g:i a",strtotime($perfRow['startDateTime'])).".<br />Please contact me by ".date("l, F j",strtotime($ASLconfirm))." to confirm this service.</p>"; }What I need is that if the ASL is "To be Arranged" there is a date that lists for $ASLconfirm that is three weeks prior to $ASLdate. The code above gives me the following: Quote An ASL Interpreted performance of this event is offered on Friday, September 28 at 7:30 pm. Please contact me by Wednesday, December 31 to confirm this service. As you can see from the output the December date is NOT three weeks prior to the September date. Where did I go wrong in my coding? Hi, I am working on a betting API, The data comes from an XML Feed. I am using a PHPPhar file to iterate the XML data, Seems to work really well. What I need to do now is iterate each "outcome" type and order it by the highest decimal to lowest decimal value (Best odds) My current array of data from the XML looks like this (See pastebin for full version) : SimpleXMLElement Object ( [Outcome] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 [name] => 1X2 ) [Bookmaker] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 8 [name] => Bet365 [isLive] => false [lastUpdate] => 2015-01-15T04:17:03 [bookieEventID] => [bookieLeagueID] => [BookieOfferTypeID] => 40 ) [Odds] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 10026743121640944 [bet] => 1 [startPrice] => 9/2 [currentPrice] => 5/1 [line] => [LastUpdate] => 2015-01-15T04:17:03 [bookieOutcomeID] => [Status] => Open ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 10026743131640944 [bet] => 2 [startPrice] => 31/50 [currentPrice] => 57/100 [line] => [LastUpdate] => 2015-01-15T04:17:03 [bookieOutcomeID] => [Status] => Open ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 10026743511640944 [bet] => X [startPrice] => 11/4 [currentPrice] => 3/1 [line] => [LastUpdate] => 2015-01-14T17:55:48 [bookieOutcomeID] => [Status] => Open ) ) ) )[1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 2 [name] => Under/Over ) [Bookmaker] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 8 [name] => Bet365 [isLive] => false [lastUpdate] => 2015-01-15T15:25:31 [bookieEventID] => [bookieLeagueID] => [BookieOfferTypeID] => 981 ) [Odds] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 14185280871640944 [bet] => Over [startPrice] => 1/20 [currentPrice] => 3/50 [line] => 0.5 [LastUpdate] => 2015-01-15T15:15:14 [bookieOutcomeID] => [Status] => Open ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 8219239561640944 [bet] => Over [startPrice] => 9/50 [currentPrice] => 1/5 [line] => 1.25 [LastUpdate] => 2015-01-15T08:30:43 [bookieOutcomeID] => [Status] => Open ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 13305582441640944 [bet] => Over [startPrice] => 29/100 [currentPrice] => 8/25 [line] => 1.5 [LastUpdate] => 2015-01-15T15:25:31 [bookieOutcomeID] => [Status] => Open ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 15814388431640944 [bet] => Over [startPrice] => 7/20 [currentPrice] => 2/5 [line] => 1.75 [LastUpdate] => 2015-01-15T08:30:43 [bookieOutcomeID] => [Status] => Open ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 9542253841640944 [bet] => Over [startPrice] => 9/20 [currentPrice] => 13/25 [line] => 2.0 [LastUpdate] => 2015-01-15T08:53:07 [bookieOutcomeID] => [Status] => Open ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 18435608691640944 [bet] => Over [startPrice] => 17/25 [currentPrice] => 77/100 [line] => 2.25 [LastUpdate] => 2015-01-15T08:53:07 [bookieOutcomeID] => [Status] => Open ) )[2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 17 [name] => Both Teams To Score ) [Bookmaker] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 8 [name] => Bet365 [isLive] => false [lastUpdate] => 2015-01-14T17:55:48 [bookieEventID] => [bookieLeagueID] => [BookieOfferTypeID] => 10150 ) [Odds] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 14294083431640944 [bet] => No [startPrice] => 83/100 [currentPrice] => 73/100 [line] => [LastUpdate] => 2015-01-14T17:55:48 [bookieOutcomeID] => [Status] => Open ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 18070790851640944 [bet] => Yes [startPrice] => 83/100 [currentPrice] => 1/1 [line] => [LastUpdate] => 2015-01-14T17:55:48 [bookieOutcomeID] => [Status] => Open ) ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 31 [name] => William Hill [isLive] => false [lastUpdate] => 2015-01-15T15:58:30 [bookieEventID] => [bookieLeagueID] => [BookieOfferTypeID] => 226344747 ) [Odds] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 11341591031640944 [bet] => No [startPrice] => 73/100 [currentPrice] => 67/100 [line] => [LastUpdate] => 2015-01-15T15:58:30 [bookieOutcomeID] => [Status] => Open ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 10996680931640944 [bet] => Yes [startPrice] => 1/1 [currentPrice] => 11/10 [line] => [LastUpdate] => 2015-01-15T15:58:30 [bookieOutcomeID] => [Status] => Open ) ) ) )Is it possible build an array of outcomes, Then sort by the best decimal price. (I have a function built that can convert the "currentPrice" to decimal. Thnak You! Looking for tutorials, but maybe the forum's quicker. Can anybody give me a loose idea how to do this? I have a sequence of pages that the user goes through to enter information. I need to move a page up to pull data before inputting to the database - to prevent some dropped entries and errors. Before, it was using info in the database to loop through and generate data. I want to do it just based on the info in an array: I want array(217 => 1, 215 => 2); to loop generate a form that loops through to create something like: Code: [Select] <form> Student one, Class 217<br> First name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> Last name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> <br><hr><br> Student one, Class 215<br> First name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> Last name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> <br><br> Student one, Class 215<br> First name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> Last name: <input type="text" name="fname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /> <br><hr><br> and so on. <input type="submit" value="Register" /></form> Here is my code:
//Grab all the monster in Monster zone 1 $q = $db->query('SELECT * from rpg_monsters where monster_zone = 1'); while ($monsterdata = $db->fetch_assoc($q)) { $monster_chance[] = $monsterdata; }and my var_dump: array (size=4) 0 => array (size=8) 'monster_id' => string '1' (length=1) 'monster_name' => string 'Merman' (length=6) 'monster_level' => string '1' (length=1) 'monster_type' => string 'Normal' (length=6) 'monster_hp' => string '10' (length=2) 'monster_dmg' => string '1' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4) 1 => array (size=8) 'monster_id' => string '2' (length=1) 'monster_name' => string 'Chris Wilson' (length=12) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Unique' (length=6) 'monster_hp' => string '25' (length=2) 'monster_dmg' => string '3' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.04' (length=4) 2 => array (size=8) 'monster_id' => string '3' (length=1) 'monster_name' => string 'Seaman Warrior' (length=14) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Magic' (length=5) 'monster_hp' => string '20' (length=2) 'monster_dmg' => string '2' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4) 3 => array (size=8) 'monster_id' => string '4' (length=1) 'monster_name' => string 'Goblin Attacker' (length=15) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Normal' (length=6) 'monster_hp' => string '15' (length=2) 'monster_dmg' => string '2' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4)As you can see, the Unique Monster (Chris Wilson) is the lowest chance at only 4%. And all the other mobs at at 10% chance to spawn. Here is my code for probability: $rate = (double) '0.03'; // 3% $max = 1 / $rate; // 100 if (mt_rand(0, $max) === 0) { // chance < $rate echo "Only 3% probability, holy cow!"; }My problem is, I'm a bit lost as how to get my probability code inside a loop and having the dynamic $rate correspond to my "chance" row. Although, I could just use ORDER BY rand() in mysql, it wouldn't let me use any probability and chances... hmmm Edited by Monkuar, 12 October 2014 - 11:12 AM. Hi, I have an array filled with values like this: Code: [Select] string(1) "Acer 1" string(2) "Acer 2" string(3) "Dell 1" string(4) "Dell 2" string(5) "Dell 3" string(6) "Dell 4" string(7) "Acer 3" string(8) "Acer 4" Is there a way to successfully remove all array strings that starts with a given value like "Acer"? I tried with this snippet, does not work: Code: [Select] foreach($array as &$value) { if(preg_match("/^Acer/", $value)) { unset($value); } } Any ideas will be appreciated! I'm working on a store locator style program. I first get and sort all zip codes based on a their distance to an original location. I then use that zip code array to find all stores in the mysql database, but when I get the results, they're no longer arranged by distance from the original location.. and I can't just sort them ascending or descending based on their zip codes because that doesn't sort them correctly either. So I need to sort the data I get from the mysql database based on their "zip_code" column and in order from the $zip array.. Here's an example of what $zip looks like.. the zip code is the key and the distance from the original zip is the value [meaning the first key is the $originalZip]: Array ( [70601] => 0 [70616] => 1.12 [70629] => 1.2 [70612] => 1.24 [70602] => 1.31 [70615] => 1.88 [70609] => 3.41 [70605] => 4.4 [70669] => 4.62 [70606] => 4.9 [70611] => 7.23 [70607] => 9.68 [70663] => 9.74 ) and then I create the $WHERE variable by each key supplied: $WHERE = "WHERE zip_code='$originalZip'"; foreach ($zip as $key => $value) { if ($key == $originalZip) {} else { $WHERE .= " OR zip_code='$key'"; } } } Then I do the query [with a paginator]: $query = query("SELECT * FROM " . $db['prefix'] . "stores $WHERE LIMIT $from, $maxResults"); but when I print the data, it doesn't keep the correct sorting format.. if (mysql_num_rows($query) > 0) { for ($i = 0; $i<mysql_num_rows($query); $i++) { $storeData = mysql_fetch_array($query, MYSQL_ASSOC); // print store information here such as $storeData['name'] $storeData['address'] $storeData['zip_code'] } } Is there an easy way to sort the mysql results based on the $zip array? When i click my submit button i am posting the following. Array ( [submitStaffOrder] => [staffMember] => Array ( [0] => 2 [1] => ANYCHEF1 ) [date] => Array ( [0] => 2020-02-18 [1] => 2020-02-18 ) [startTime] => Array ( [0] => 11:01 [1] => 10:10 ) [finishTime] => Array ( [0] => 11:01 [1] => 10:01 ) [delExisting] => Array ( [0] => [1] => toDel ) ) I would like to update/insert if delExisting is blank and delete if it has toDel in there. I have the following but i am pretty sure the if is not working. $date = $_POST['date']; $stime = $_POST['startTime']; $ftime = $_POST['finishTime']; $del = $_POST['delExisting']; $staff = $_POST['staffMember']; $stmt = $conn -> prepare(" INSERT IGNORE INTO ssm_staff_order (job_id, staff_id, staff_start_time, staff_finish_time, staff_start_date, staff_finish_date) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE staff_start_time = VALUES(staff_start_time), staff_finish_time = VALUES(staff_finish_time); "); $delstmt = $conn -> prepare(" DELETE FROM ssm_staff_order WHERE staff_id = ? AND job_id = ? AND staff_start_date = ? "); foreach ($staff as $key => $staffId) { if ($del == '') { $start = $date[$key].' '.$stime[$key]; $finish = $date[$key].' '.$ftime[$key]; $stmt -> bind_param('isssss', $jid, $staffId, $start, $finish, $date[$key], $date[$key]); $stmt -> execute(); } if ($del == 'toDel') { $delstmt -> bind_param('sis', $staffId, $jid, $date[$key]); $delstmt -> execute(); } } } Can i do what i am trying to do or am i way off here?
I struggle with arrays Edited February 24, 2020 by AdamhumbugI am trying to get rows from MYSQL table (attachment) based on: Select last five rows where status_id = 1 Select last two rows where status_id = 2*I did use UNION with two SELECT queries to get whole data as one array. Now on PHP side... I have first block for rows having status_id 1 so if there are rows having status_id 1 then PHP should display the data otherwise if there is no row having status_id 1 then PHP should print NO DATA only once. I have second block for rows having status_id 2 so if there are rows having status_id 2 then PHP should display the data otherwise if there is no row having status_id 2 then PHP should print NO DATA only once. I did use foreach loop then within loop i did use if condition to check status_id of rows. it works fine when i omit NO DATA part but when i add it. the result shows both rows and NO DATA in first block when there are one or more rows having status_id 1 but no row having status_id 2 Which made me believe that i was doing it the wrong way. Please guide me *PS: I know its PHP section the thread should be related to PHP problem but... is it right to use UNION in query? or should i post a new thread in relevant section for guidance?
Hello. I am editing a plugin that is grabbing a multidimensional array, then breaking it out into a foreach statement and doing stuff with the resulting data. What I am trying to do is edit the array before it gets to the foreach statement. I want to look and see if there is a key/value combination that exists, and if it does remove that entire subarray, then reform the array and pass it to a new variable. The current variable Code: [Select] $arrSlides returns several subarrays that look like something like this (I remove unimportant variables for the sake of brevity): Code: [Select] Array ( [0] => Array ( [slide_active] => 1 ) [1] => Array ( [slide_active] => 0 ) ) What I want to do is look and see if one of these subarrays contains the key slide_active with a value of 0. If it contains a value of zero, I want to dump the whole subarray altogether, then reform the multidimensional array back into the variable Code: [Select] $arrSlides. I have tried a few array functions but have not had any luck. Any suggestions? Thanks in advance, Jason Hello. I have written this script where user restaurant owner can add his place to the database of all local restaurants. (insert basic information into database, add up to 3 images, thumbnail creation, insert image information to database). It works well on localhost, but i would like some suggestions for improvement. Im not very sure of its structure, it may not execute well once it is online. And i also think there are too many "IF's". But i really have no idea how to do it any other way. Thanks for all the suggestions. Code: [Select] <?php if(!defined('PROTECTION') || constant('PROTECTION') != 'demover') { echo "fuck off intruder!"; exit; } $naziv = mysql_real_escape_string($_POST['Naziv']); $naslov = mysql_real_escape_string($_POST['Naslov']); $kraj = mysql_real_escape_string($_POST['Kraj']); $telefon = mysql_real_escape_string($_POST['Telefon']); $web = "http://www.".mysql_real_escape_string($_POST['Spletna']); $gm = mysql_real_escape_string($_POST['Lokacija']); //$gmaps = gmParse($gm); $gmaps = 10; $fill="INSERT INTO bpoint (sName, sAddr, placeID, sPhone, sWeb, sGMaps, companyID) VALUES ('$naziv','$naslov','$kraj','$telefon','$web','$gmaps','$cID')"; if (mysql_query($fill)) { $lastID=mysql_insert_id(); $path="./truck/".$cID."/".$lastID; $pname=$_FILES["pic"]["tmp_name"]; $num=0; if (count($_FILES["pic"]) && mkdir($path, 0777)) { include "thumbs.php"; foreach($pname as $imag){ $bname=date("YmdHis").$num; $num++; $finalpath=$path."/".$bname.".jpg"; $finalthumb=$path."/".$bname."_thumb.jpg"; if($imag!="") { if (move_uploaded_file($imag, $finalpath)) { make_thumb($finalpath,$finalthumb,150); mysql_query("INSERT INTO images (name, companyID) VALUES ('$finalpath', '$cID')"); } } } } unset($_FILES["pic"]); } else {die(mysql_error());} ?> I suck with arrays, there I said it . With that said, hopefully someone can help me here. I have two multi-dimensional arrays called $allteams and $chosenteams (the contents of which are listed below). I simply want to compare them and make a new array of the items that are in the first array ($allteams) but NOT in the second array ($chosenteams). NOTE: I tried to use array_diff() but couldn't get it to work since they are multidimensional... FYI, I'm also confused why the info appears to be listed twice but I think that just has to do with associative vs. numeric arrays (i.e. I think I just need to specify one and the amount info would be cut in half), but I'll research this more on my own as it seems like it has to be easy to find $allteams Array ( => Array ( => 1 [teamid] => 1 [1] => Philadelphia [teamcity] => Philadelphia [2] => Eagles [teamname] => Eagles ) [1] => Array ( => 2 [teamid] => 2 [1] => Dallas [teamcity] => Dallas [2] => Cowboys [teamname] => Cowboys ) [2] => Array ( => 3 [teamid] => 3 [1] => New York [teamcity] => New York [2] => Giants [teamname] => Giants ) [3] => Array ( => 4 [teamid] => 4 [1] => Washington [teamcity] => Washington [2] => Redskins [teamname] => Redskins ) [4] => Array ( => 5 [teamid] => 5 [1] => Detroit [teamcity] => Detroit [2] => Lions [teamname] => Lions ) [5] => Array ( => 6 [teamid] => 6 [1] => Minnesota [teamcity] => Minnesota [2] => Vikings [teamname] => Vikings ) [6] => Array ( => 7 [teamid] => 7 [1] => Green Bay [teamcity] => Green Bay [2] => Packers [teamname] => Packers ) [7] => Array ( => 8 [teamid] => 8 [1] => Chicago [teamcity] => Chicago [2] => Bears [teamname] => Bears ) [8] => Array ( => 9 [teamid] => 9 [1] => Tampa Bay [teamcity] => Tampa Bay [2] => Buccs [teamname] => Buccs ) [9] => Array ( => 10 [teamid] => 10 [1] => New Orleans [teamcity] => New Orleans [2] => Saints [teamname] => Saints ) [10] => Array ( => 11 [teamid] => 11 [1] => Carolina [teamcity] => Carolina [2] => Panthers [teamname] => Panthers ) [11] => Array ( => 12 [teamid] => 12 [1] => Atlanta [teamcity] => Atlanta [2] => Falcons [teamname] => Falcons ) [12] => Array ( => 13 [teamid] => 13 [1] => Seattle [teamcity] => Seattle [2] => Seahawks [teamname] => Seahawks ) [13] => Array ( => 14 [teamid] => 14 [1] => San Francisco [teamcity] => San Francisco [2] => 49ers [teamname] => 49ers ) [14] => Array ( => 15 [teamid] => 15 [1] => St. Louis [teamcity] => St. Louis [2] => Rams [teamname] => Rams ) [15] => Array ( => 16 [teamid] => 16 [1] => Arizona [teamcity] => Arizona [2] => Cardinals [teamname] => Cardinals ) [16] => Array ( => 17 [teamid] => 17 [1] => New York [teamcity] => New York [2] => Jets [teamname] => Jets ) [17] => Array ( => 18 [teamid] => 18 [1] => Miami [teamcity] => Miami [2] => Dolphins [teamname] => Dolphins ) [18] => Array ( => 19 [teamid] => 19 [1] => Buffalo [teamcity] => Buffalo [2] => Bills [teamname] => Bills ) [19] => Array ( => 20 [teamid] => 20 [1] => New England [teamcity] => New England [2] => Patriots [teamname] => Patriots ) [20] => Array ( => 21 [teamid] => 21 [1] => Baltimore [teamcity] => Baltimore [2] => Ravens [teamname] => Ravens ) [21] => Array ( => 22 [teamid] => 22 [1] => Cincinnati [teamcity] => Cincinnati [2] => Bengals [teamname] => Bengals ) [22] => Array ( => 23 [teamid] => 23 [1] => Pittsburgh [teamcity] => Pittsburgh [2] => Steelers [teamname] => Steelers ) [23] => Array ( => 24 [teamid] => 24 [1] => Cleveland [teamcity] => Cleveland [2] => Browns [teamname] => Browns ) [24] => Array ( => 25 [teamid] => 25 [1] => Houston [teamcity] => Houston [2] => Texans [teamname] => Texans ) [25] => Array ( => 26 [teamid] => 26 [1] => Tennessee [teamcity] => Tennessee [2] => Titans [teamname] => Titans ) [26] => Array ( => 27 [teamid] => 27 [1] => Jacksonville [teamcity] => Jacksonville [2] => Jaguars [teamname] => Jaguars ) [27] => Array ( => 28 [teamid] => 28 [1] => Indianapolis [teamcity] => Indianapolis [2] => Colts [teamname] => Colts ) [28] => Array ( => 29 [teamid] => 29 [1] => Denver [teamcity] => Denver [2] => Broncos [teamname] => Broncos ) [29] => Array ( => 30 [teamid] => 30 [1] => Kansas City [teamcity] => Kansas City [2] => Chiefs [teamname] => Chiefs ) [30] => Array ( => 31 [teamid] => 31 [1] => Oakland [teamcity] => Oakland [2] => Raiders [teamname] => Raiders ) [31] => Array ( => 32 [teamid] => 32 [1] => San Diego [teamcity] => San Diego [2] => Chargers [teamname] => Chargers ) ) $chosenteams Array ( => Array ( => 2 [teamid] => 2 [1] => Dallas [teamcity] => Dallas [2] => Cowboys [teamname] => Cowboys ) [1] => Array ( => 3 [teamid] => 3 [1] => New York [teamcity] => New York [2] => Giants [teamname] => Giants ) ) Again, I just want to compare those two multi-dimensional arrays and end up with another array that only has the items that are in the first but NOT in the second. So now I'm trying to do it the way below using simply "array_push" Code: [Select] $remainingteams = array(); foreach($allteams as $teamname=> $value) { if (in_array($teamname, $chosenteams)) { } else { array_push($remainingteams,$teamname); } } My end result based on the way the arrays are in this example should be... $remainingteams (really the only difference is that the Cowboys and Giants info is gone) Array ( => Array ( => 1 [teamid] => 1 [1] => Philadelphia [teamcity] => Philadelphia [2] => Eagles [teamname] => Eagles ) [3] => Array ( => 4 [teamid] => 4 [1] => Washington [teamcity] => Washington [2] => Redskins [teamname] => Redskins ) [4] => Array ( => 5 [teamid] => 5 [1] => Detroit [teamcity] => Detroit [2] => Lions [teamname] => Lions ) [5] => Array ( => 6 [teamid] => 6 [1] => Minnesota [teamcity] => Minnesota [2] => Vikings [teamname] => Vikings ) [6] => Array ( => 7 [teamid] => 7 [1] => Green Bay [teamcity] => Green Bay [2] => Packers [teamname] => Packers ) [7] => Array ( => 8 [teamid] => 8 [1] => Chicago [teamcity] => Chicago [2] => Bears [teamname] => Bears ) [8] => Array ( => 9 [teamid] => 9 [1] => Tampa Bay [teamcity] => Tampa Bay [2] => Buccs [teamname] => Buccs ) [9] => Array ( => 10 [teamid] => 10 [1] => New Orleans [teamcity] => New Orleans [2] => Saints [teamname] => Saints ) [10] => Array ( => 11 [teamid] => 11 [1] => Carolina [teamcity] => Carolina [2] => Panthers [teamname] => Panthers ) [11] => Array ( => 12 [teamid] => 12 [1] => Atlanta [teamcity] => Atlanta [2] => Falcons [teamname] => Falcons ) [12] => Array ( => 13 [teamid] => 13 [1] => Seattle [teamcity] => Seattle [2] => Seahawks [teamname] => Seahawks ) [13] => Array ( => 14 [teamid] => 14 [1] => San Francisco [teamcity] => San Francisco [2] => 49ers [teamname] => 49ers ) [14] => Array ( => 15 [teamid] => 15 [1] => St. Louis [teamcity] => St. Louis [2] => Rams [teamname] => Rams ) [15] => Array ( => 16 [teamid] => 16 [1] => Arizona [teamcity] => Arizona [2] => Cardinals [teamname] => Cardinals ) [16] => Array ( => 17 [teamid] => 17 [1] => New York [teamcity] => New York [2] => Jets [teamname] => Jets ) [17] => Array ( => 18 [teamid] => 18 [1] => Miami [teamcity] => Miami [2] => Dolphins [teamname] => Dolphins ) [18] => Array ( => 19 [teamid] => 19 [1] => Buffalo [teamcity] => Buffalo [2] => Bills [teamname] => Bills ) [19] => Array ( => 20 [teamid] => 20 [1] => New England [teamcity] => New England [2] => Patriots [teamname] => Patriots ) [20] => Array ( => 21 [teamid] => 21 [1] => Baltimore [teamcity] => Baltimore [2] => Ravens [teamname] => Ravens ) [21] => Array ( => 22 [teamid] => 22 [1] => Cincinnati [teamcity] => Cincinnati [2] => Bengals [teamname] => Bengals ) [22] => Array ( => 23 [teamid] => 23 [1] => Pittsburgh [teamcity] => Pittsburgh [2] => Steelers [teamname] => Steelers ) [23] => Array ( => 24 [teamid] => 24 [1] => Cleveland [teamcity] => Cleveland [2] => Browns [teamname] => Browns ) [24] => Array ( => 25 [teamid] => 25 [1] => Houston [teamcity] => Houston [2] => Texans [teamname] => Texans ) [25] => Array ( => 26 [teamid] => 26 [1] => Tennessee [teamcity] => Tennessee [2] => Titans [teamname] => Titans ) [26] => Array ( => 27 [teamid] => 27 [1] => Jacksonville [teamcity] => Jacksonville [2] => Jaguars [teamname] => Jaguars ) [27] => Array ( => 28 [teamid] => 28 [1] => Indianapolis [teamcity] => Indianapolis [2] => Colts [teamname] => Colts ) [28] => Array ( => 29 [teamid] => 29 [1] => Denver [teamcity] => Denver [2] => Broncos [teamname] => Broncos ) [29] => Array ( => 30 [teamid] => 30 [1] => Kansas City [teamcity] => Kansas City [2] => Chiefs [teamname] => Chiefs ) [30] => Array ( => 31 [teamid] => 31 [1] => Oakland [teamcity] => Oakland [2] => Raiders [teamname] => Raiders ) [31] => Array ( => 32 [teamid] => 32 [1] => San Diego [teamcity] => San Diego [2] => Chargers [teamname] => Chargers ) ) Can anyone help me figure this out? i've been trying for hours (I know, that's pathetic ) I wish to return the object in an array with the highest index where its index falls between between integers, and return null should one not exist. For instance, with the following and a min and max of 10,000 and 15,000, it should return OBJ4, and with a min and max of 15,000 and 20,000 it should return NULL. Any thoughts? Thanks function getObj(int $min, int $max):?OBJ { $list=[ 12314=>'OBJ1', 321=>'OBJ2', 42142=>'OBJ3', 14314=>'OBJ4', 123=>'OBJ5', 13314=>'OBJ6' ]; return getIt($list, $min, $max); }
|