Good afternoon, please help me. At me when parsing the result of parsing is not displayed.
link my php file https://dropmefiles.com/cv4Q2
Please correct where I was wrong. Or help to rewrite a little code so that it displays the result of the parser.
Already tried all the options, it does not work in any way. My knowledge here is not enough.
1 file
part 1
function getForecastXML($cid='579432') {
$cid = "579432";
$hoffset = "4";
$appid= "d86ad74d22ce9cc528d8baee65acd408";
$lang= "ru";
$days = array();
$xml = #file_get_contents("http://api.openweathermap.org/data/2.5/forecast?id=$cid&mode=xml&appid=$appid&lang=$lang&type=like");
if ($xml===false) { return;} else {
$xml = simplexml_load_string($xml);
$cityname = (string)$xml->location->name;
$weekdays[0] = "Воскресенье";
$weekdays[1] = "Понедельник";
$weekdays[2] = "Вторник";
$weekdays[3] = "Среда";
$weekdays[4] = "Четверг";
$weekdays[5] = "Пятница";
$weekdays[6] = "Суббота";
if (count($xml->forecast->time)>0){
foreach ($xml->forecast->time as $fpart) {
$forecast = array();
$attr = $fpart->attributes();
$forecast['t']['min'] = (string)round(($fpart->temperature->attributes()->min)-273,15,PHP_ROUND_HALF_UP);
$forecast['t']['min'] = $forecast['t']['min'] > 0 ? "+".$forecast['t']['min'] : $forecast['t']['min'];
$forecast['t']['max'] = (string)round(($fpart->temperature->attributes()->max)-273,15,PHP_ROUND_HALF_UP);
$forecast['t']['max'] = $forecast['t']['max'] > 0 ? "+".$forecast['t']['max'] : $forecast['t']['max'];
$forecast['p']['min'] = (string)round($fpart->pressure->attributes()->value,0,PHP_ROUND_HALF_UP);
// $forecast['p']['max'] = (string)$fpart->PRESSURE->attributes()->max;
$forecast['w']['min'] = (string)round($fpart->windSpeed->attributes()->mps,0,PHP_ROUND_HALF_UP);
//$forecast['w']['max'] = (string)$fpart->WIND->attributes()->max;
//$forecast['w']['rumb'] = (string)$fpart->WIND->attributes()->direction;
$forecast['h']['min'] = (string)$fpart->humidity->attributes()->value;
//$forecast['h']['max'] = (string)$fpart->RELWET->attributes()->max;
$forecast['symb'] = (string)$fpart->symbol->attributes()->name;
$forecast['pict'] = (string)$fpart->symbol->attributes()->var;
$date = date('c',strtotime($hoffset.' hours',strtotime($attr['from'])));
$hour = date('H',strtotime($date));
$forecast['timestamp'] =strtotime($date);
$date = strtotime($date);
$dayofweek = date('w',$date);
$date = $weekdays[$dayofweek]." ".date('d.m',$date);
if ($forecast['timestamp'] > time()){
$days[$date][$hour] = $forecast;
}
}
} else {$days=array();}
}
//return array($cityname,$days);
return [$cityname => $days];
//echo [$cityname => $days];
}
part 2
$outputData = array();
if (count($this->forecast) > 0) {
foreach ($this->forecast as $date => $daypart) {
$outputData[] = $date;
foreach ($daypart as $dp => $data) {
$outputData[] = str_pad($dp, 2, '0', STR_PAD_LEFT);
$outputData[] = $data['symb'];
$outputData[] = $data['t']['min'];
$outputData[] = $data['t']['max'];
if (($data['p']['min']) > 0) {
$outputData[] = "Давление " . round($data['p']['min'] * 0.75006375541921) . "мм. рт. ст.";
}
}
}
} else {
$outputData[] = "В данный момент информация о погоде отсутствует";
}
echo implode(' ', $outputData);
I'm using Laravel 5.3 and facing problems regarding the session which is not being preserved when I hit the URL with query string(UTM Querystring). It works fine without querystring and maintains the session.
mywebsite.com/booking (Works fine)
mywebsite.com/booking?utm_source=affiliate&utm_medium=mailer&utm_campaign=Ad2click (Destroys session as well cookies)
Wondering, what could be the reason?
public function bookProduct(Request $request){
$zone = $request->zone;
$records = Zone::where('zone_name',$zone)->get();
foreach($records as $record){
$zone_id = $record->id;
}
if ( Session::get('LAST_ACTIVITY') && (time() - Session::get('LAST_ACTIVITY') > 1200 )){
echo 'expired';
}
else{
$CheckOTP = Session::get('otp');
/* Check if User Entered OTP Matches System Generated OTP */
if ( $CheckOTP == $request->get_otp ) {
/* Create new Customer */
$recordCount = Customer::where('email', $request->customer_email)->orWhere('contact_number',$request->customer_contact_no)->count();
if( $recordCount > 0 ){
Customer::where('contact_number', $request->customer_contact_no)->update(['door_number' => $request->customer_pickup_door_no, 'building_name' => $request->customer_pickup_building_name, 'street_name' => $request->customer_pickup_street_name, 'area' => $request->customer_pickup_area, 'landmark' => $request->customer_pickup_landmark, 'pincode' => $request->customer_pickup_pincode, 'city'=>$request->customer_city]);
}
if($recordCount == 0 || $recordCount == ""){
$customer = new Customer;
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
$randomPass = implode($pass);
$password = Hash::make('a');
$customer->customer_name = $request->customer_name;
$customer->email = $request->customer_email;
$customer->contact_number = $request->customer_contact_no;
$customer->password = $password;
$customer->door_number = $request->customer_pickup_door_no;
//$customer->street_name = $request->customer_pickup_street_name;
//$customer->building_name = $request->customer_pickup_building_name;
$customer->area = $request->customer_pickup_area;
$customer->landmark = $request->customer_pickup_landmark;
$customer->pincode = $request->customer_pickup_pincode;
$customer->city = $request->customer_city;
$customer->save();
$id = $customer->id;
$measurement = new Measurement;
$measurement->customer_id = $id;
$address = $request->customer_pickup_door_no .",".$request->customer_pickup_area .",".$request->customer_pickup_landmark .",". $request->customer_city.",". $request->customer_pickup_pincode;
$measurement->save();
$datas = $this->create_customer($request->customer_contact_no,$request->customer_name, $request->customer_email,$address,$request->customer_pickup_pincode);
$this->save_customers($request->customer_contact_no);
}
else{
$address = $request->customer_pickup_door_no .",".$request->customer_pickup_area .",".$request->customer_pickup_landmark .",". $request->customer_city.",". $request->customer_pickup_pincode;
$datas = $this->create_customer($request->customer_contact_no,$request->customer_name, $request->customer_email,$address,$request->customer_pickup_pincode);
$this->save_customers($request->customer_contact_no);
$fetchCustomer = Customer::where('email', $request->customer_email)->orWhere('contact_number',$request->customer_contact_no)->get();
foreach( $fetchCustomer as $customerId ){
$id = $customerId->id;
}
}
/* Store New Booking */
/* Pickup address same as shipping address*/
if( $request->duplicate_address == 'on'){
$request->customer_shipping_door_no = $request->customer_pickup_door_no;
//$request->customer_shipping_street_name = $request->customer_pickup_street_name;
//$request->customer_shipping_building_name = $request->customer_pickup_building_name;
$request->customer_shipping_area = $request->customer_pickup_area;
$request->customer_shipping_landmark = $request->customer_pickup_landmark;
$request->customer_shipping_pincode = $request->customer_pickup_pincode;
}
$booking = new Booking;
$booking->customer_id = $id;
$booking->look_id = Session::get("lookIds");
$booking->time_slot_id = $request->slot;
$booking->booking_date = strtr($request->booking_date, '/', '-');
$booking->booking_date = date('Y-m-d', strtotime($booking->booking_date));
$booking->door_number = $request->customer_shipping_door_no;
//$booking->street_name = $request->customer_shipping_street_name;
//$booking->building_name = $request->customer_shipping_building_name;
$booking->landmark = $request->customer_shipping_landmark;
$booking->pincode = $request->customer_shipping_pincode;
$booking->city = $request->customer_city;
$booking->area = $request->customer_shipping_area;
$booking->fabric_availability = $request->fabric_material;
$booking->otp = $CheckOTP;
$booking->http_user_agent = $_SERVER['HTTP_USER_AGENT'];
$zones = Zone::where('zone_name',$request->zone)->get();
foreach( $zones as $zone){
$booking->zone_id = $zone->id;
}
/* Fetch Latitude & Longitude from address */
//$address = $request->customer_pickup_door_no.' ,'.$request->customer_pickup_street_name.' ,'.$request->customer_pickup_building_name.' ,'.$request->customer_pickup_landmark;
$address = $request->customer_pickup_door_no.' ,'.$request->customer_pickup_landmark.' ,'.$request->customer_shipping_area;
$prepAddr = str_replace(' ','+',$address);
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
if( $output->status != "ZERO_RESULTS" ){
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;
}
else{
$booking->latitude = "";
$booking->longitude = "";
}
$lastId = Booking::max('id');
$lastId = $lastId+1;
$booking->booking_id = 'BK'.date("ymd").str_pad($lastId, 4, '0', STR_PAD_LEFT);
$checkCouponApply = $request->check_coupon_apply;
if($checkCouponApply == '1'){
$couponCode = $request->discount_coupon;
$booking->coupon_code = $request->discount_coupon;
$getDiscountPercentage = Discount::where('coupon_code',$couponCode)->pluck('coupon_percentage');
$getDiscountPercentage = $getDiscountPercentage[0];
Discount::where('coupon_code',$booking->coupon_code)->decrement('remaining_user_count');
}
$booking->save();
Session::set('bookingId', $booking->id);
if($request->trouser > 0 && $request->shirt > 0){
Session::set('productBought', 'Shirt & Trouser');
}
else if($request->trouser>0){
Session::set('productBought', 'Trouser');
}
else if($request->shirt>0){
Session::set('productBought', 'Shirt');
}
/* Store products data for Booking */
$trouserRecord = Categories::where('category_name','Trouser')->pluck('id');
$shirtRecord = Categories::where('category_name','Shirt')->pluck('id');
$trouserPrice = ProductPrice::where('zone_id',$zone_id)
->where('category_id',$trouserRecord[0])
->pluck('price');
$shirtPrice = ProductPrice::where('zone_id',$zone_id)
->where('category_id',$shirtRecord[0])
->pluck('price');
$shirtUnitPrice = $shirtPrice[0];
$trouserUnitPrice = $trouserPrice[0];
$products = array('trouser' => array('count' => $request->trouser, 'category' => $trouserRecord[0], 'price'=>$trouserPrice[0], 'unit_price'=>$trouserUnitPrice), 'shirt' => array('count' => $request->shirt, 'category' => $shirtRecord[0], 'price'=>$shirtPrice[0], 'unit_price'=>$shirtUnitPrice));
foreach($products as $product){
for($i=0;$i<$product['count'];$i++){
$subBooking = new SubBooking;
//Calculate tax tmount for each lined up product and save relavant data
$subBooking->booking_id = $booking->id;
if($product['category'] == '3'){
$subBooking->category_name = 'Shirt';
}
else if($product['category'] == '4'){
$subBooking->category_name = 'Trouser';
}
$setTaxes = Tax::all();
foreach($setTaxes as $taxes){
$tax[$taxes->tax_type] = $product['unit_price']*($taxes->percentage/100);
$tax[$taxes->tax_type.'Percentage'] = $taxes->percentage;
}
$subBooking->service_tax = $tax['Service Tax'];
$subBooking->service_tax_percentage = $tax['Service TaxPercentage'];
$subBooking->swachh_bharat = $tax['Swachh Bharat'];
$subBooking->swachh_bharat_percentage = $tax['Swachh BharatPercentage'];
$subBooking->krishi_kalyan = $tax['Krishi Kalyan'];
$subBooking->krishi_kalyan_percentage = $tax['Krishi KalyanPercentage'];
$subBooking->category_id = $product['category'];
$subBooking->unit_price = $product['unit_price'];
$subBooking->unit_price = $product['unit_price'];
$subBooking->quantity = 1;
$subBooking->save();
}
}
if($subBooking){
$this->storeReportingData('new');
}
$email = $request->customer_email;
$booking_date_new = date("d M Y", strtotime($booking->booking_date));
$time_slot_data = TimeSlot::where('id',$booking->time_slot_id)->first();
$start = date("g:i a", strtotime($time_slot_data['start']));
$end = date("g:i a", strtotime($time_slot_data['end']));
$msg = "Thank you for booking with us. Your booking ref number is: $booking->booking_id and our appointment with you is on $booking_date_new ($start - $end).";
$action = 'New Booking';
$description = "Booking has been created";
$this->saveLog($booking->id, $action, $description);
Session::forget('lookIds');
$contact_no = $request->customer_contact_no;;
$urlapi = "https://api-in.bsmart.in/api/v3/sendsms/plain?";
$user = "USER";
$password = "SECRET";
$senderid = "SENDER_ID";
$pin = mt_rand(1000, 9999);
$msg_order_confirmation = urlencode("$msg");
$msg2 = "Dear Customer, Please spare 45 minutes of your valuable time with our stylists for a perfect styling experience.";
$sms_url = $urlapi."User=".$user."&Password=".$password."&Sender=".$senderid."&GSM=91".$contact_no."&SMSText=".$msg_order_confirmation;
// Initialize session and set URL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $sms_url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);
$email_message = $msg." ".$msg2;
//$this->sendEmail($email,$email_message);
$this->sendSMS($contact_no,$msg2);
$sub_bookings = SubBooking::where('booking_id',$booking->id)->where('quantity','<>', 0)->get();
$data = array();
foreach($sub_bookings as $sub_booking){
$quantity = $sub_booking->quantity;
$category_data = Categories::where('id',$sub_booking->category_id)->first();
$category_name = $category_data['category_name'];
$data[] = array('quantity'=>$quantity,'category_name'=>$category_name);
}
$appointment_date = date("d M Y", strtotime($booking->booking_date));
$time_slot_data = TimeSlot::where('id',$booking->time_slot_id)->first();
$start = date("g:i a", strtotime($time_slot_data['start']));
$end = date("g:i a", strtotime($time_slot_data['end']));
$customer_data = Customer::where('id',$booking->customer_id)->first();
$customer_name = $customer_data['customer_name'];
$email_data = array('email'=>$email,'customer_name'=>$customer_name,'from'=>'notifications-noreply#raymondcustomtailoring.com','from_name'=>'Raymond','appointment_date'=>$appointment_date,'appointment_id'=>$booking->booking_id,'customer_name'=>$customer_name,'address'=>$address,'pincode'=>$request->customer_shipping_pincode,'data'=>$data,'start'=>$start,'end'=>$end);
/*Mail::send(['html'=>'confirm'],$email_data, function( $message ) use ($email_data)
{
$message->to( $email_data['email'] )->from($email_data['from'],$email_data['from_name'] )->subject($email_data['appointment_id'].' Appointment Confirmed');
});*/
//return $booking->id;
}
else{
echo 'mismatched';
}
}
}
I currently have a site that uploads a CSV and displays it in a preview table as a form that can be edited (if any CSV values are wrong).
It works great, but I need to insert this into a database table with any edits that are made within the form. I have an array that puts the uploaded CSV into this form, but now I think I need to create a new CSV from this form and submit THAT CSV into the database. I've seen some tutorials but I'm unclear on how to do it from this table/form.
Here is the code for the existing preview form:
if(isset($_POST['preview']))
{
ini_set('auto_detect_line_endings', true);
$file = $_FILES["file"]["tmp_name"];
$handle = fopen($file, "r");
$maxPreviewRows = PHP_INT_MAX; // this will be ~2 billion on 32-bit system, or ~9 quintillion on 64-bit system
$hasHeaderRow = true;
?><form><?
echo '<table>';
/*WE WILL NEED TO QA CONDITIONS AND HIGHLIGHT IN RED HERE. ALSO NEED BORDER STYLINGS*/
if ($hasHeaderRow) {
$headerRow = fgetcsv($handle);
echo '<thead><tr>';
foreach($headerRow as $value) {
echo "<th>$value</th>";
}
echo '</tr></thead>';
}
echo '<tbody>';
$rowCount = 0;
while ($row = fgetcsv($handle)) {
echo '<tr>';
foreach($row as $value) {
echo "<td>$value</td>";
}
echo '</tr>';
if (++$rowCount > $maxPreviewRows) {
break;
}
}
echo '</tbody></table>';
}
?></form>
Since this doesn't have values for each field in the form, I'm unsure of the best way to create a CSV from this and insert it into my staging table.
UPDATE - the below code is my first attempt at using my CSV upload array
if(isset($_POST['submit']))
{
$file = $_FILES["file"]["tmp_name"];
$handle = fopen($file, "r");
$filesop = fgetcsv($handle, 0, ",");
while (($filesop = fgetcsv($handle)) !== FALSE) {
$coldata = array();
$coldata["orderNumber"] = $filesop[0];
$coldata["workOrderPacket"] = $filesop[1];
$coldata["workOrderNum"] = $filesop[2];
$coldata["lowSideMIUNumArriv"] = $filesop[3];
$coldata["lowSideMIUNumDepart"] = $filesop[4];
$coldata["highSideMIUNumArriv"] = $filesop[5];
$coldata["highSideMIUNumDepart"] = $filesop[6];
$coldata["accountNum"] = $filesop[7];
$coldata["filler1"] = $filesop[8];
$coldata["address"] = $filesop[9];
$coldata["filler2"] = $filesop[10];
$coldata["date"] = $filesop[11];
$coldata["utility"] = $filesop[12];
$coldata["serialNumber"] = $filesop[13];
$coldata["serviceName"] = $filesop[14];
$coldata["locationNotes"] = $filesop[15];
$coldata["locationComments"] = $filesop[16];
$coldata["filler3"] = $filesop[17];
$coldata["WaterValveArriv"] = $filesop[18];
$coldata["WaterValveDepart"] = $filesop[19];
$coldata["meterSize"] = $filesop[20];
$coldata["meterType"] = $filesop[21];
$coldata["manufacturer"] = $filesop[22];
$coldata["registration"] = $filesop[23];
$coldata["technician"] = $filesop[24];
$coldata["linePressurePSI"] = $filesop[25];
$coldata["filler4"] = $filesop[26];
$coldata["filler5"] = $filesop[27];
$coldata["lowSideRrBefore"] = $filesop[28];
$coldata["highSideRrBefore"] = $filesop[29];
$coldata["lowSideRrAfter"] = $filesop[30];
$coldata["highSideRrAfter"] = $filesop[31];
$coldata["vgOxygen"] = $filesop[32];
$coldata["vgCombustGas"] = $filesop[33];
$coldata["vgCarbonMon"] = $filesop[34];
$coldata["vgHydroSulf"] = $filesop[35];
$coldata["test1TestRateGPM"] = $filesop[36];
$coldata["test1MeterVol"] = $filesop[37];
$coldata["test1TesterVol"] = $filesop[38];
$coldata["test1Accuracy"] = $filesop[39];
$coldata["test1CorrectAcc"] = $filesop[40];
$coldata["test2TestRateGPM"] = $filesop[41];
$coldata["test2MeterVol"] = $filesop[42];
$coldata["test2TesterVol"] = $filesop[43];
$coldata["test2Accuracy"] = $filesop[44];
$coldata["test2CorrectAcc"] = $filesop[45];
$coldata["test3TestRateGPM"] = $filesop[46];
$coldata["test3MeterVol"] = $filesop[47];
$coldata["test3TesterVol"] = $filesop[48];
$coldata["test3Accuracy"] = $filesop[49];
$coldata["test3CorrectAcc"] = $filesop[50];
$coldata["test4TestRateGPM"] = $filesop[51];
$coldata["test4MeterVol"] = $filesop[52];
$coldata["test4TesterVol"] = $filesop[53];
$coldata["test4Accuracy"] = $filesop[54];
$coldata["test4CorrectAcc"] = $filesop[55];
$coldata["test5TestRateGPM"] = $filesop[56];
$coldata["test5MeterVol"] = $filesop[57];
$coldata["test5TesterVol"] = $filesop[58];
$coldata["test5Accuracy"] = $filesop[59];
$coldata["test5CorrectAcc"] = $filesop[60];
$coldata["test6TestRateGPM"] = $filesop[61];
$coldata["test6MeterVol"] = $filesop[62];
$coldata["test6TesterVol"] = $filesop[63];
$coldata["test6Accuracy"] = $filesop[64];
$coldata["test6CorrectAcc"] = $filesop[65];
$coldata["test7TestRateGPM"] = $filesop[66];
$coldata["test7MeterVol"] = $filesop[67];
$coldata["test7TesterVol"] = $filesop[68];
$coldata["test7Accuracy"] = $filesop[69];
$coldata["test7CorrectAcc"] = $filesop[70];
$coldata["test8TestRateGPM"] = $filesop[71];
$coldata["test8MeterVol"] = $filesop[72];
$coldata["test8TesterVol"] = $filesop[73];
$coldata["test8Accuracy"] = $filesop[74];
$coldata["test8CorrectAcc"] = $filesop[75];
$coldata["inletValveLoc"] = $filesop[76];
$coldata["inletValveSize"] = $filesop[77];
$coldata["InletValveType"] = $filesop[78];
$coldata["inletValveCond"] = $filesop[79];
$coldata["outletValveLoc"] = $filesop[80];
$coldata["outletValveSize"] = $filesop[81];
$coldata["outletValveType"] = $filesop[82];
$coldata["outletValveCond"] = $filesop[83];
$coldata["bypassValveLoc"] = $filesop[84];
$coldata["bypassValveSize"] = $filesop[85];
$coldata["bypassValveType"] = $filesop[86];
$coldata["bypassValveCond"] = $filesop[87];
$coldata["vaultLength"] = $filesop[88];
$coldata["vaultWidth"] = $filesop[89];
$coldata["vaultHeight"] = $filesop[90];
$coldata["meterLocation"] = $filesop[91];
$coldata["testPort"] = $filesop[92];
$coldata["testPortInstalled"] = $filesop[93];
$coldata["testPortSize"] = $filesop[94];
$coldata["picture"] = $filesop[95];
$coldata["timeTested"] = $filesop[96];
$coldata["comments"] = $filesop[97];
$coldata["testResults"] = $filesop[98];
$coldata["retest"] = $filesop[99];
$coldata["test1TestRateGPM2"] = $filesop[100];
$coldata["test1MeterVol2"] = $filesop[101];
$coldata["test1TesterVol2"] = $filesop[102];
$coldata["test1Accuracy2"] = $filesop[103];
$coldata["test1CorrectAcc2"] = $filesop[104];
$coldata["test2TestRateGPM2"] = $filesop[105];
$coldata["test2MeterVol2"] = $filesop[106];
$coldata["test2TesterVol2"] = $filesop[107];
$coldata["test2Accuracy2"] = $filesop[108];
$coldata["test2CorrectAcc2"] = $filesop[109];
$coldata["test3TestRateGPM2"] = $filesop[110];
$coldata["test3MeterVol2"] = $filesop[111];
$coldata["test3TesterVol2"] = $filesop[112];
$coldata["test3Accuracy2"] = $filesop[113];
$coldata["test3CorrectAcc2"] = $filesop[114];
$coldata["test4TestRateGPM2"] = $filesop[115];
$coldata["test4MeterVol2"] = $filesop[116];
$coldata["test4TesterVol2"] = $filesop[117];
$coldata["test4Accuracy2"] = $filesop[118];
$coldata["test4CorrectAcc2"] = $filesop[119];
$coldata["test5TestRateGPM2"] = $filesop[120];
$coldata["test5MeterVol2"] = $filesop[121];
$coldata["test5TesterVol2"] = $filesop[122];
$coldata["test5Accuracy2"] = $filesop[123];
$coldata["test5CorrectAcc2"] = $filesop[124];
$coldata["test6TestRateGPM2"] = $filesop[125];
$coldata["test6MeterVol2"] = $filesop[126];
$coldata["test6TesterVol2"] = $filesop[127];
$coldata["test6Accuracy2"] = $filesop[128];
$coldata["test6CorrectAcc2"] = $filesop[129];
$coldata["test7TestRateGPM2"] = $filesop[130];
$coldata["test7MeterVol2"] = $filesop[131];
$coldata["test7TesterVol2"] = $filesop[132];
$coldata["test7Accuracy2"] = $filesop[133];
$coldata["test7CorrectAcc2"] = $filesop[134];
$coldata["test8TestRateGPM2"] = $filesop[135];
$coldata["test8MeterVol2"] = $filesop[136];
$coldata["test8TesterVol2"] = $filesop[137];
$coldata["test8Accuracy2"] = $filesop[138];
$coldata["test8CorrectAcc2"] = $filesop[139];
$coldata["filler6"] = $filesop[140];
$coldata["filler7"] = $filesop[141];
$coldata["filler8"] = $filesop[142];
$coldata["filler9"] = $filesop[143];
$coldata["filler10"] = $filesop[144];
$coldata["filler11"] = $filesop[145];
$coldata["filler12"] = $filesop[146];
$coldata["serviceAddCorrect"] = $filesop[147];
$coldata["serviceLoccCorrect"] = $filesop[148];
$coldata["meterNumberCorrect"] = $filesop[149];
$coldata["lowRegisterCorrect"] = $filesop[150];
$coldata["lowRegisterType"] = $filesop[151];
$coldata["lowRegisterSize"] = $filesop[152];
$coldata["highRegisterCorrect"] = $filesop[153];
$coldata["highRegisterSize"] = $filesop[154];
$coldata["highRegisterType"] = $filesop[155];
$coldata["meterLidType"] = $filesop[156];
$coldata["meterLidMaterial"] = $filesop[157];
$coldata["lidFit"] = $filesop[158];
$coldata["lidCondition"] = $filesop[159];
$coldata["antennaeMountCor"] = $filesop[160];
$coldata["antennaePosition"] = $filesop[161];
$coldata["registerCondition"] = $filesop[162];
$coldata["MIUwire"] = $filesop[163];
$coldata["registerPinArriv"] = $filesop[164];
$coldata["registerPinDepart"] = $filesop[165];
$coldata["vaultType"] = $filesop[166];
$coldata["vaultSafe"] = $filesop[167];
$coldata["vaultLadder"] = $filesop[168];
$coldata["workOrderType"] = $filesop[169];
$coldata["workOrderLocation"] = $filesop[170];
$coldata["completeMeter"] = $filesop[171];
$coldata["ume"] = $filesop[172];
$coldata["discChamber"] = $filesop[173];
$coldata["turbineChamber"] = $filesop[174];
$coldata["automaticValve"] = $filesop[175];
$coldata["strainer"] = $filesop[176];
$coldata["lowRegister"] = $filesop[177];
$coldata["highRegister"] = $filesop[178];
$coldata["miu"] = $filesop[179];
$coldata["antennae"] = $filesop[180];
$coldata["calibrationVane"] = $filesop[181];
$coldata["meterLeakRepaired"] = $filesop[182];
$coldata["workOrderType2"] = $filesop[183];
$coldata["strainerPresent"] = $filesop[184];
$coldata["apparentLeak"] = $filesop[185];
$coldata["leakLocation"] = $filesop[186];
$coldata["leakType"] = $filesop[187];
$coldata["locateBypassValve"] = $filesop[188];
$coldata["locateInletValve"] = $filesop[189];
$coldata["locateOutletValve"] = $filesop[190];
$coldata["PreformShutdown"] = $filesop[191];
$coldata["turnOnWater"] = $filesop[192];
$coldata["repairLid"] = $filesop[193];
$coldata["repairVault"] = $filesop[194];
$coldata["repairLadder"] = $filesop[195];
$coldata["repairLeak"] = $filesop[196];
$coldata["repairBypassValve"] = $filesop[197];
$coldata["repairInletValve"] = $filesop[198];
$coldata["repairOutletValve"] = $filesop[199];
$coldata["latitude"] = $filesop[200];
$coldata["longitude"] = $filesop[201];
$coldata["onsiteSurveyTestCost"] = $filesop[202];
$coldata["onsiteSurveyTestRepairCost"] = $filesop[203];
$coldata["offsiteSurveyTestCost"] = $filesop[204];
$coldata["offsiteSurveyTestRepairCost"] = $filesop[205];
$coldata["onsiteTestOnlyCost"] = $filesop[206];
$coldata["onsiteTestRepairOnlyCost"] = $filesop[207];
$coldata["onsiteRepairOnly"] = $filesop[208];
$coldata["testPort2"] = $filesop[209];
$coldata["repairCompleteMeterReplacement"] = $filesop[210];
$coldata["repairCompleteMeterReplacementLaborCost"] = $filesop[211];
$coldata["umeCost"] = $filesop[212];
$coldata["umeLaborCost"] = $filesop[213];
$coldata["rotatingLowSideDiskChamber"] = $filesop[214];
$coldata["rotatingLowSideDiskChamberLaborCost"] = $filesop[215];
$coldata["turbineChamberCost"] = $filesop[216];
$coldata["turbineChamberLaborCost"] = $filesop[217];
$coldata["automaticValveCost"] = $filesop[218];
$coldata["automaticValveLaborCost"] = $filesop[219];
$coldata["strainerCost"] = $filesop[220];
$coldata["strainerLaborCost"] = $filesop[221];
$coldata["lowRegisterCost"] = $filesop[222];
$coldata["lowRegisterLaborCost"] = $filesop[223];
$coldata["highRegisterCost"] = $filesop[224];
$coldata["highRegisterLaborCost"] = $filesop[225];
$coldata["miuCost"] = $filesop[226];
$coldata["miuLaborCost"] = $filesop[227];
$coldata["totalCost"] = $filesop[228];
I've read some texts and searched topics, but nothing help me. I'm beginner in PHP. I have array where are variables $qA01_1 up to $qA30_5 and their values can be different 0 or 1 or 5. From array I would like to find all variables with value 1 and make sum. Same for number 5.
$qA01_1 = $_SESSION['qA01_1'];
$qA01_2 = $_SESSION['qA01_2'];
$qA01_3 = $_SESSION['qA01_3'];
$qA01_4 = $_SESSION['qA01_4'];
$qA01_5 = $_SESSION['qA01_5'];
$qA02_1 = $_SESSION['qA02_1'];
$qA02_2 = $_SESSION['qA02_2'];
$qA02_3 = $_SESSION['qA02_3'];
$qA02_4 = $_SESSION['qA02_4'];
$qA02_5 = $_SESSION['qA02_5'];
$qA03_1 = $_SESSION['qA03_1'];
$qA03_2 = $_SESSION['qA03_2'];
$qA03_3 = $_SESSION['qA03_3'];
$qA03_4 = $_SESSION['qA03_4'];
$qA03_5 = $_SESSION['qA03_5'];
$qA04_1 = $_SESSION['qA04_1'];
$qA04_2 = $_SESSION['qA04_2'];
$qA04_3 = $_SESSION['qA04_3'];
$qA04_4 = $_SESSION['qA04_4'];
$qA04_5 = $_SESSION['qA04_5'];
$qA05_1 = $_SESSION['qA05_1'];
$qA05_2 = $_SESSION['qA05_2'];
$qA05_3 = $_SESSION['qA05_3'];
$qA05_4 = $_SESSION['qA05_4'];
$qA05_5 = $_SESSION['qA05_5'];
$qA06_1 = $_SESSION['qA06_1'];
$qA06_2 = $_SESSION['qA06_2'];
$qA06_3 = $_SESSION['qA06_3'];
$qA06_4 = $_SESSION['qA06_4'];
$qA06_5 = $_SESSION['qA06_5'];
$qA07_1 = $_SESSION['qA07_1'];
$qA07_2 = $_SESSION['qA07_2'];
$qA07_3 = $_SESSION['qA07_3'];
$qA07_4 = $_SESSION['qA07_4'];
$qA07_5 = $_SESSION['qA07_5'];
$qA08_1 = $_SESSION['qA08_1'];
$qA08_2 = $_SESSION['qA08_2'];
$qA08_3 = $_SESSION['qA08_3'];
$qA08_4 = $_SESSION['qA08_4'];
$qA08_5 = $_SESSION['qA08_5'];
$qA09_1 = $_SESSION['qA09_1'];
$qA09_2 = $_SESSION['qA09_2'];
$qA09_3 = $_SESSION['qA09_3'];
$qA09_4 = $_SESSION['qA09_4'];
$qA09_5 = $_SESSION['qA09_5'];
$qA10_1 = $_SESSION['qA10_1'];
$qA10_2 = $_SESSION['qA10_2'];
$qA10_3 = $_SESSION['qA10_3'];
$qA10_4 = $_SESSION['qA10_4'];
$qA10_5 = $_SESSION['qA10_5'];
$qA11_1 = $_SESSION['qA11_1'];
$qA11_2 = $_SESSION['qA11_2'];
$qA11_3 = $_SESSION['qA11_3'];
$qA11_4 = $_SESSION['qA11_4'];
$qA11_5 = $_SESSION['qA11_5'];
$qA12_1 = $_SESSION['qA12_1'];
$qA12_2 = $_SESSION['qA12_2'];
$qA12_3 = $_SESSION['qA12_3'];
$qA12_4 = $_SESSION['qA12_4'];
$qA12_5 = $_SESSION['qA12_5'];
$qA13_1 = $_SESSION['qA13_1'];
$qA13_2 = $_SESSION['qA13_2'];
$qA13_3 = $_SESSION['qA13_3'];
$qA13_4 = $_SESSION['qA13_4'];
$qA13_5 = $_SESSION['qA13_5'];
$qA14_1 = $_SESSION['qA14_1'];
$qA14_2 = $_SESSION['qA14_2'];
$qA14_3 = $_SESSION['qA14_3'];
$qA14_4 = $_SESSION['qA14_4'];
$qA14_5 = $_SESSION['qA14_5'];
$qA15_1 = $_SESSION['qA15_1'];
$qA15_2 = $_SESSION['qA15_2'];
$qA15_3 = $_SESSION['qA15_3'];
$qA15_4 = $_SESSION['qA15_4'];
$qA15_5 = $_SESSION['qA15_5'];
$qA16_1 = $_SESSION['qA16_1'];
$qA16_2 = $_SESSION['qA16_2'];
$qA16_3 = $_SESSION['qA16_3'];
$qA16_4 = $_SESSION['qA16_4'];
$qA16_5 = $_SESSION['qA16_5'];
$qA17_1 = $_SESSION['qA17_1'];
$qA17_2 = $_SESSION['qA17_2'];
$qA17_3 = $_SESSION['qA17_3'];
$qA17_4 = $_SESSION['qA17_4'];
$qA17_5 = $_SESSION['qA17_5'];
$qA18_1 = $_SESSION['qA18_1'];
$qA18_2 = $_SESSION['qA18_2'];
$qA18_3 = $_SESSION['qA18_3'];
$qA18_4 = $_SESSION['qA18_4'];
$qA18_5 = $_SESSION['qA18_5'];
$qA19_1 = $_SESSION['qA19_1'];
$qA19_2 = $_SESSION['qA19_2'];
$qA19_3 = $_SESSION['qA19_3'];
$qA19_4 = $_SESSION['qA19_4'];
$qA19_5 = $_SESSION['qA19_5'];
$qA20_1 = $_SESSION['qA20_1'];
$qA20_2 = $_SESSION['qA20_2'];
$qA20_3 = $_SESSION['qA20_3'];
$qA20_4 = $_SESSION['qA20_4'];
$qA20_5 = $_SESSION['qA20_5'];
$qA21_1 = $_SESSION['qA21_1'];
$qA21_2 = $_SESSION['qA21_2'];
$qA21_3 = $_SESSION['qA21_3'];
$qA21_4 = $_SESSION['qA21_4'];
$qA21_5 = $_SESSION['qA21_5'];
$qA22_1 = $_SESSION['qA22_1'];
$qA22_2 = $_SESSION['qA22_2'];
$qA22_3 = $_SESSION['qA22_3'];
$qA22_4 = $_SESSION['qA22_4'];
$qA22_5 = $_SESSION['qA22_5'];
$qA23_1 = $_SESSION['qA23_1'];
$qA23_2 = $_SESSION['qA23_2'];
$qA23_3 = $_SESSION['qA23_3'];
$qA23_4 = $_SESSION['qA23_4'];
$qA23_5 = $_SESSION['qA23_5'];
$qA24_1 = $_SESSION['qA24_1'];
$qA24_2 = $_SESSION['qA24_2'];
$qA24_3 = $_SESSION['qA24_3'];
$qA24_4 = $_SESSION['qA24_4'];
$qA24_5 = $_SESSION['qA24_5'];
$qA25_1 = $_SESSION['qA25_1'];
$qA25_2 = $_SESSION['qA25_2'];
$qA25_3 = $_SESSION['qA25_3'];
$qA25_4 = $_SESSION['qA25_4'];
$qA25_5 = $_SESSION['qA25_5'];
$qA26_1 = $_SESSION['qA26_1'];
$qA26_2 = $_SESSION['qA26_2'];
$qA26_3 = $_SESSION['qA26_3'];
$qA26_4 = $_SESSION['qA26_4'];
$qA26_5 = $_SESSION['qA26_5'];
$qA27_1 = $_SESSION['qA27_1'];
$qA27_2 = $_SESSION['qA27_2'];
$qA27_3 = $_SESSION['qA27_3'];
$qA27_4 = $_SESSION['qA27_4'];
$qA27_5 = $_SESSION['qA27_5'];
$qA28_1 = $_SESSION['qA28_1'];
$qA28_2 = $_SESSION['qA28_2'];
$qA28_3 = $_SESSION['qA28_3'];
$qA28_4 = $_SESSION['qA28_4'];
$qA28_5 = $_SESSION['qA28_5'];
$qA29_1 = $_SESSION['qA29_1'];
$qA29_2 = $_SESSION['qA29_2'];
$qA29_3 = $_SESSION['qA29_3'];
$qA29_4 = $_SESSION['qA29_4'];
$qA29_5 = $_SESSION['qA29_5'];
$qA30_1 = $_POST['qA30_1'];
$qA30_2 = $_POST['qA30_2'];
$qA30_1 = (isset($_POST['qA30_1'])) ? $_POST['qA30_1'] : 0;
$qA30_2 = (isset($_POST['qA30_2'])) ? $_POST['qA30_2'] : 0;
$qA30_3 = (isset($_POST['qA30_3'])) ? $_POST['qA30_3'] : 0;
$qA30_4 = (isset($_POST['qA30_4'])) ? $_POST['qA30_4'] : 0;
$qA30_5 = (isset($_POST['qA30_5'])) ? $_POST['qA30_5'] : 0;
Here is my proposal which do not work. I thing that I should to do something with "array" .
// Sum of all numbers 1
$sumOne = 0;
for ($i = 0; $i <= 3; $i++) {
for($j = 0; $j <= 9; $j++) {
for($k = 1; $k <= 5; $k++){
$u = 'qA_' . $i . $j. '_' . $k;
if ($u==1){
$sumOnet+=1;
}
}
}
}
echo "<br/>SumOne:" . " " . round($sumOne[0], 0);
You really should stick with an array. If you define an array within the $_SESSION array and use that it will be much simpler:
$_SESSION['data']['qA01_1'] = 0;
$_SESSION['data']['qA01_2'] = 1;
$_SESSION['data']['qA01_3'] = 5;
$counts = array_count_values($_SESSION['data']);
if(isset($counts[0])) { echo $counts[0]; } // sum of any 0s is 0 so here is the count
if(isset($counts[1])) { echo $counts[1]; } // sum of any 1s will be the count
if(isset($counts[5])) { echo $counts[5] * 5; }
If I understand the question correctly, you want to sum up all individual values in your array.
You can use array_count_values() for that, it returns you the number of occurances of each value where the value itself is the key:
foreach (array_count_values($_SESSION) as $value => $count) {
echo 'sum of ' . $value . ' values: ' . ($value * $count) . "<br>";
}
No idea where the POST variables fit in though...
I have one problem with my php code. I create the campaign and create audiences tag (remarketing => website visitors => code) from PHP.
The problem is when I try include audience to campaign. Code whose I'm using:
github example
My code view like this:
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
$adGroupId = $group_id;
$operations = array();
$campaign = new Campaign();
$campaign->id = $google_data['google_id'];
$campaign->advertisingChannelType = 'DISPLAY';
$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = false;
$networkSetting->targetSearchNetwork = false;
$networkSetting->targetContentNetwork = true;
$campaign->networkSetting = $networkSetting;
$operation = new CampaignOperation();
$operation->operand = $campaign;
$operation->operator = 'SET';
$operations[] = $operation;
$result = $campaignService->mutate($operations);
$return_array['id'] = $result->value[0]->id;
$userListService = $user->GetService('AdwordsUserListService', ADWORDS_VERSION);
$conversionTrackerService =
$user->GetService('ConversionTrackerService', ADWORDS_VERSION);
$conversionType = new UserListConversionType();
$conversionType->name = $name . uniqid();
$userList = new BasicUserList();
$userList->name = $name . uniqid();
$userList->conversionTypes = array($conversionType);
$userList->status = 'OPEN';
$userList->membershipLifeSpan = $day;
$operation = new UserListOperation();
$operation->operand = $userList;
$operation->operator = 'ADD';
$operations = array($operation);
$result = $userListService->mutate($operations);
$userList = $result->value[0];
$static_user_id = $userList->id;
// print_r($userList->id);
// exit;
sleep(1);
$selector = new Selector();
$selector->fields = array('Id');
$selector->predicates[] =
new Predicate('Id', 'IN', array($userList->conversionTypes[0]->id));
$page = $conversionTrackerService->get($selector);
$conversionTracker = $page->entries[0];
$tag = $conversionTracker->snippet;
$audience_id = $userList->conversionTypes[0]->id;
$campaignId = $return_array['id'];
$adGroupService = $user->GetService('AdGroupService', ADWORDS_VERSION);
$operations = array();
$adGroup = new AdGroup();
$adGroup->id = $google_data['google_group_id'];
$adGroup->campaignId = $campaignId;
$targetingSetting = new TargetingSetting();
$targetingSetting->details[] = new TargetingSettingDetail('PLACEMENT', false);
$adGroup->settings[] = $targetingSetting;
$operation = new AdGroupOperation();
$operation->operand = $adGroup;
$operation->operator = 'SET';
$operations[] = $operation;
$result = $adGroupService->mutate($operations);
$return_array['id_group'] = $result->value[0]->id;
$adGroupId = $return_array['id_group'];
$adGroupCriterionService = $user->GetService('AdGroupCriterionService', ADWORDS_VERSION);
$criterionUserList = new CriterionUserList();
$criterionUserList->id = $static_user_id;
$criterionUserList->type = "USER_LIST";
$operations = array();
$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->adGroupId = $adGroupId;
$adGroupCriterion->criterion = $criterionUserList;
$adGroupCriteria[] = $adGroupCriterion;
$operation = new AdGroupCriterionOperation();
$operation->operand = $adGroupCriterion;
$operation->operator = 'SET';
$operations[] = $operation;
$result = $adGroupCriterionService->mutate($operations);
$return_array['remarketing_email'] = $result->value[0]->criterion->id;
And when I running this code, I've got output:
An error has occurred:215 [EntityNotFound.INVALID_ID # operations[0].operand.criterion.id; trigger:'CriterionId{id=414978678}']