Improve PHP execution speed - php

Please how do i improve the speed of php code. I have over 1580 lines of code that needs to be process about 103,000 data set. Presently this code takes more than 5 minutes to process 1 data set. It contains 30 for loops and 168 conditional statement.
$tnu =0; $tcp=0; $tnup = 0;
if($SsNoCourses[$sessionCounter] != 0){
//echo $SsNoCourses[$sessionCounter]."</br>";
$secondSemesterExist = "True";
$actualSemesterCounter = $actualSemesterCounter + 1;
$lastComputedSemesterId = $actualSemesterCounter;
for($i = 0; $i<$noOfCoursesS; $i++){
if ($sessionCounter == 1){
$tnu = $tnu + $SsY1Courses[$i][2];
$tcp = $tcp + $SsY1Courses[$i][2]*$SsY1Courses[$i][4];
if ($SsY1Courses[$i][4] != 0){$tnup = $tnup + $SsY1Courses[$i][2];}
}else if ($sessionCounter == 2){
$tnu = $tnu + $SsY2Courses[$i][2];
$tcp = $tcp + $SsY2Courses[$i][2]*$SsY2Courses[$i][4];
if ($SsY2Courses[$i][4] != 0){$tnup = $tnup + $SsY2Courses[$i][2];}
}else if ($sessionCounter == 3){
$tnu = $tnu + $SsY3Courses[$i][2];
$tcp = $tcp + $SsY3Courses[$i][2]*$SsY3Courses[$i][4];
if ($SsY3Courses[$i][4] != 0){$tnup = $tnup + $SsY3Courses[$i][2];}
}else if ($sessionCounter == 4){
$tnu = $tnu + $SsY4Courses[$i][2];
$tcp = $tcp + $SsY4Courses[$i][2]*$SsY4Courses[$i][4];
if ($SsY4Courses[$i][4] != 0){$tnup = $tnup + $SsY4Courses[$i][2];}
}else if ($sessionCounter == 5){
$tnu = $tnu + $SsY5Courses[$i][2];
$tcp = $tcp + $SsY5Courses[$i][2]*$SsY5Courses[$i][4];
if ($SsY5Courses[$i][4] != 0){$tnup = $tnup + $SsY5Courses[$i][2];}
}else if ($sessionCounter == 6){
$tnu = $tnu + $SsY6Courses[$i][2];
$tcp = $tcp + $SsY6Courses[$i][2]*$SsY6Courses[$i][4];
if ($SsY6Courses[$i][4] != 0){$tnup = $tnup + $SsY6Courses[$i][2];}
}else if ($sessionCounter == 7){
$tnu = $tnu + $SsY7Courses[$i][2];
$tcp = $tcp + $SsY7Courses[$i][2]*$SsY7Courses[$i][4];
if ($SsY7Courses[$i][4] != 0){$tnup = $tnup + $SsY7Courses[$i][2];}
}else if ($sessionCounter == 8){
$tnu = $tnu + $SsY8Courses[$i][2];
$tcp = $tcp + $SsY8Courses[$i][2]*$SsY8Courses[$i][4];
if ($SsY8Courses[$i][4] != 0){$tnup = $tnup + $SsY8Courses[$i][2];}

Related

how to reduce number of variables PHP

My code checks and updates the number of apartments a building has with different bedrooms (1,2,3,4,studio) and calculates their avg min rent price and avg max rent price for particular type of room. How do I reduce the number of variables in this code so its easier to read and work with, if I can do it with arrays and foreach loop how can I use them in this code?
$room_one = $room_two = $room_three = $room_four = $room_studio = 0;
$rentmin_one = $rentmin_two = $rentmin_three = $rentmin_four = $rentmin_studio = 0;
$rentmax_one = $rentmax_two = $rentmax_three = $rentmax_four = $rentmax_studio = 0;
foreach ($nodes as $node) {
$field_bedrooms = "input field value";
$field_rentmin = "input field value";
$field_rentmax = "input field value";
foreach ($field_bedrooms as $field_bedroom) {
if (!is_null($field_bedroom) && !empty($field_bedroom)) {
$bedrooms_nid = $field_bedroom['target_id'];
$bedrooms_vocab = $this->load($bedrooms_nid);
$bedroom_value = $bedrooms_vocab->getName();
if ($bedroom_value == 1) {
$room_one++;
$rentmin_one = $rentmin_one + $field_rentmin;
$rentmax_one = $rentmax_one + $field_rentmax;
}
elseif ($bedroom_value == 2) {
$room_two++;
$rentmin_two = $rentmin_two + $field_rentmin;
$rentmax_two = $rentmax_two + $field_rentmax;
}
elseif ($bedroom_value == 3) {
$room_three++;
$rentmin_three = $rentmin_three + $field_rentmin;
$rentmax_three = $rentmax_three + $field_rentmax;
}
elseif ($bedroom_value == 4 || $bedroom_value == '4+') {
$room_four++;
$rentmin_four = $rentmin_four + $field_rentmin;
$rentmax_four = $rentmax_four + $field_rentmax;
}
elseif ($bedroom_value == 'Studio') {
$room_studio++;
$rentmin_studio = $rentmin_studio + $field_rentmin;
$rentmax_studio = $rentmax_studio + $field_rentmax;
}
}
}
}
$avg_minrent['one'] = !empty($rentmin_one) && !empty($room_one) ? $rentmin_one / $room_one : '';
$avg_maxrent['one'] = !empty($rentmax_one) && !empty($room_one) ? $rentmax_one / $room_one : '';
$avg_minrent['two'] = !empty($rentmin_two) && !empty($room_two) ? $rentmin_two / $room_two : '';
$avg_minrent['three'] = !empty($rentmin_three) && !empty($room_three) ? $rentmin_three / $room_three : '';
$avg_minrent['four'] = !empty($rentmin_four) && !empty($room_four) ? $rentmin_four / $room_four : '';
$avg_minrent['studio'] = !empty($rentmin_studio) && !empty($room_studio) ? $rentmin_studio / $room_studio : '';
$avg_maxrent['two'] = !empty($rentmax_two) && !empty($room_two) ? $rentmax_two / $room_two : '';
$avg_maxrent['three'] = !empty($rentmax_three) && !empty($room_three) ? $rentmax_three / $room_three : '';
$avg_maxrent['four'] = !empty($rentmax_four) && !empty($room_four) ? $rentmax_four / $room_four : '';
$avg_maxrent['studio'] = !empty($rentmax_studio) && !empty($room_studio) ? $rentmax_studio / $room_studio : '';
return [f
$avg_minrent,
$avg_maxrent,
];

how to do not update value on update function?

i want this code should not be run if user call upate route code
if($getDistanceValue * 1000 > 300){
if($chk_ord == 0)
{
$order->chk_ord_vst = 1;
}
elseif($chk_ord != 0){
$order->chk_ord_vst = $chk_ord + 1;
}
}
elseif($getDistanceValue * 1000 <= 300 ){
if($chk_ord >= 4){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 3){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 2){
$order->chk_ord_vst = 1;
}
elseif($chk_ord <= 1){
$order->chk_ord_vst = 0;
}
}
i am using a same fucntion to update or store order but on update i donot want to run above code i know it is very simple but i am a student and learning help me here it is controller function first user create order the if wants to update then we use get function to pass value to edit view and then pass again to stor function
public function storeOrder(Request $request , $update = null , $customer_id){
$order = !is_null($update) ? Order::find($update) : new Order();
$cus_det = explode("-", $request->customer_id);
$tt_amount = array_sum($request->amount) + $request->old_balance;
if(is_null ($update))
$balance = $tt_amount + $request->old_balance;
$auth_id = Auth::id();
if(Auth::user()->role == 4){
$auth_id = Customer::where('user_id', $auth_id)->first()->created_by;
}
$order->customer_id = $cus_det[0];
$order->user_id = Auth::id();
$order->ot_id = !is_null($update) ? $order->ot_id : $auth_id;
$order->unit = array_sum($request->unit);
$order->amount = $tt_amount;
$order->subtotal = array_sum($request->amount);
$order->order_comments = $request->order_comments;
if( Auth::user()->role == 5){
$order->location_url_ot = $request->location_url_ot;
$order->received_amount = 0;
}
else{
$order->received_amount = $request->received_amount;
}
$order->discount = $request->discount;
$order->order_date= date('Y/m/d', strtotime($request->order_date));
if($tt_amount >= $request->received_amount){
$order->amount_left = ($tt_amount - $request->received_amount - $request->discount);
}
else{
$order->advance = $request->received_amount - $tt_amount;
$order->amount_left = $request->old_balance - $request->received_amount - $request->discount;
}
$checkB = $this->checkMinBalance($cus_det[0] , $order->amount_left);
if($checkB){
return redirect()->back()->with('error' , 'Customer Balance Limit Exceeded ( Limit is '.$checkB.' )');
}
if($request->has('important')){
$order->is_important=1;
}
if($request->has('urgent')){
$order->urgent = urgent ;
}
$getothomDistanceValue = ($this->getothomDistance($order) * 1.37);
$getDistanceValue = ($this->getDistance($order) * 1.37);
$old_order = Order::where('customer_id' , $order->customer_id)->orderBy('id' , 'desc')->get();
$chk_ord = $old_order[0]->chk_ord_vst;
if($getDistanceValue * 1000 > 300){
if($chk_ord == 0)
{
$order->chk_ord_vst = 1;
}
elseif($chk_ord != 0){
$order->chk_ord_vst = $chk_ord + 1;
}
}
elseif($getDistanceValue * 1000 <= 300 ){
if($chk_ord >= 4){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 3){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 2){
$order->chk_ord_vst = 1;
}
elseif($chk_ord <= 1){
$order->chk_ord_vst = 0;
}
}
$order->save();
}
What I get from your question is you are using the same storeOrder function for storing and updating an order.
When you are using it for update, You need the id from $request->id or any other parameter from the front-end so that you can find that specific Order and then call update(). If you get the $id, You can just check if the order exists or not like below:
$order_exists = Order::find($request->id);
if(!isset($order_exists))
{
if($getDistanceValue * 1000 > 300){
if($chk_ord == 0)
{
$order->chk_ord_vst = 1;
}
elseif($chk_ord != 0){
$order->chk_ord_vst = $chk_ord + 1;
}
}
elseif($getDistanceValue * 1000 <= 300 ){
if($chk_ord >= 4){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 3){
$order->chk_ord_vst = 2;
}
elseif($chk_ord == 2){
$order->chk_ord_vst = 1;
}
elseif($chk_ord <= 1){
$order->chk_ord_vst = 0;
}
}
}
// then $order->save() when done
One way to go about this would be to pass a parameter through the form and check.
But if you have route names defined, you could also do something like:
if(\Illuminate\Support\Facades\Route::current()->getName() === 'orders.create'){
// logic here
}
However, I must say that I consider the later solution an anti-pattern.

php update successful but not updating the databse

I got problem with this code. I've tried so many possible solution but still no update in phpmyadmin. The code run successfully through the footer since it say "Successfully Updated" but still no changes
<?php
if ($_POST){
$con = mysql_connect("localhost", "root", "pass123");
if (!$con){die('Could not connect:' . mysql_error());}
mysql_select_db("testing", $con) or die('Error:' . mysql_error());
$entry = $_GET['entry'];
$branch_id = $_POST['branch_id'];
$outletname = $_POST['outletname'];
$date = $_POST['date'];
$q11a = $_POST['q11a'];
$q12a = $_POST['q12a'];
$q13a = $_POST['q13a'];
$q14a = $_POST['q14a'];
$q15a = $_POST['q15a'];
$q16a = $_POST['q16a'];
$q17a = $_POST['q17a'];
$q18a = $_POST['q18a'];
$q19a = $_POST['q19a'];
$q20a = $_POST['q20a'];
$q21a = $_POST['q21a'];
$q22a = $_POST['q22a'];
$q23a = $_POST['q23a'];
$q24a = $_POST['q24a'];
$q25a = $_POST['q25a'];
$q26a = $_POST['q26a'];
$q27a = $_POST['q27a'];
$q28a = $_POST['q28a'];
$q29a = $_POST['q29a'];
$q30a = $_POST['q30a'];
$q31a = $_POST['q31a'];
$q32a = $_POST['q32a'];
$q33a = $_POST['q33a'];
$q34a = $_POST['q34a'];
$q35a = $_POST['q35a'];
$q36a = $_POST['q36a'];
$q37a = $_POST['q37a'];
$q38a = $_POST['q38a'];
$q39a = $_POST['q39a'];
$q40a = $_POST['q40a'];
$q41a = $_POST['q41a'];
$q42a = $_POST['q42a'];
$q43a = $_POST['q43a'];
$q44a = $_POST['q44a'];
$q45a = $_POST['q45a'];
$q46a = $_POST['q46a'];
$q47a = $_POST['q47a'];
$q48a = $_POST['q48a'];
$q49a = $_POST['q49a'];
$q50a = $_POST['q50a'];
$q51a = $_POST['q51a'];
$q52a = $_POST['q52a'];
$q53a = $_POST['q53a'];
$q54a = $_POST['q54a'];
$q55a = $_POST['q55a'];
$q56a = $_POST['q56a'];
$q57a = $_POST['q57a'];
$q58a = $_POST['q58a'];
$q59a = $_POST['q59a'];
$q60a = $_POST['q60a'];
$q61a = $_POST['q61a'];
$q62a = $_POST['q62a'];
$q63a = $_POST['q63a'];
$q64a = $_POST['q64a'];
$q65a = $_POST['q65a'];
$q66a = $_POST['q66a'];
$q67a = $_POST['q67a'];
$q68a = $_POST['q68a'];
$q69a = $_POST['q69a'];
$q70a = $_POST['q70a'];
$q71a = $_POST['q71a'];
$q72a = $_POST['q72a'];
$q73a = $_POST['q73a'];
$q74a = $_POST['q74a'];
$q75a = $_POST['q75a'];
$q76a = $_POST['q76a'];
$q78a = $_POST['q78a'];
$q78a1 = $_POST['q78a1'];
$q79a = $_POST['q79a'];
$q79a1 = $_POST['q79a1'];
$q80a = $_POST['q80a'];
$q81a = $_POST['q81a'];
$q82a = $_POST['q82a'];
$q83a = $_POST['q83a'];
$q84a = $_POST['q84a'];
$q85a = $_POST['q85a'];
$timein = $_POST['timein'];
$HOR = $_POST['HOR'];
$MODa = $_POST['MODa'];
$KL = $_POST['KL'];
$ateambox = $_POST['ateambox'];
$box35 = $_POST['box35'];
$box36 = $_POST['box36'];
$box41 = $_POST['box41'];
$box50 = $_POST['box50'];
$box53 = $_POST['box53'];
$box54 = $_POST['box54'];
$box55 = $_POST['box55'];
$box61a = $_POST['box61a'];
$box61aa = $_POST['box61aa'];
$box61b = $_POST['box61b'];
$box61bb = $_POST['box61bb'];
$box61c = $_POST['box61c'];
$box61cc =$_POST['box61cc'];
$box61d = $_POST['box61d'];
$box61dd = $_POST['box61dd'];
$box61e = $_POST['box61e'];
$box61ee = $_POST['box61ee'];
$box73a = $_POST['box73a'];
$box73b = $_POST['box73b'];
$box73c = $_POST['box73c'];
$box74a = $_POST['box74a'];
$box74b = $_POST['box74b'];
$box74c = $_POST['box74c'];
$box74d = $_POST['box74d'];
$box74e = $_POST['box74e'];
$box74f = $_POST['box74f'];
$box74g = $_POST['box74g'];
$box74h = $_POST['box74h'];
$box74i = $_POST['box74i'];
$box74j = $_POST['box74j'];
$box75a = $_POST['box75a'];
$box75b = $_POST['box75b'];
$box75c = $_POST['box75c'];
$box75d = $_POST['box75d'];
$box75e = $_POST['box75e'];
$box75f = $_POST['box75f'];
$box75g = $_POST['box75g'];
$box75h = $_POST['box75h'];
$box75i = $_POST['box75i'];
$box75j = $_POST['box75j'];
$box75k = $_POST['box75k'];
$box75l = $_POST['box75l'];
$box75m = $_POST['box75m'];
$box75n = $_POST['box75n'];
$box75o = $_POST['box75o'];
$box75p = $_POST['box75p'];
$box75q = $_POST['box75q'];
$box75r = $_POST['box75r'];
$box78a = $_POST['box78a'];
$box78b = $_POST['box78b'];
$box78c = $_POST['box78c'];
$box78d = $_POST['box78d'];
$box78e = $_POST['box78e'];
$box78f = $_POST['box78f'];
$box78g = $_POST['box78g'];
$box78h = $_POST['box78h'];
$box78i = $_POST['box78i'];
$box78j = $_POST['box78j'];
$box78k = $_POST['box78k'];
$box78l = $_POST['box78l'];
$box78m = $_POST['box78m'];
$box79a = $_POST['box79a'];
$box79b = $_POST['box79b'];
$box79c = $_POST['box79c'];
$box79d = $_POST['box79d'];
$box91a = $_POST['box91a'];
$box91b = $_POST['box91b'];
$box91c = $_POST['box91c'];
$box92a = $_POST['box92a'];
$box92b = $_POST['box92b'];
if ($q11a == -1){
$naarrival = $naarrival + 1;
}
if ($q12a == -1){
$naarrival = $naarrival + 1;
}
if ($q14a == -1){
$naarrival = $naarrival + 1;
}
if ($q15a == -1){
$naarrival = $naarrival + 1;
}
if ($q26a == -1){
$nadining = $nadining + 1;
}
if ($q31a == -1){
$nadining = $nadining + 1;
}
if ($q32a == -1){
$nadining = $nadining + 1;
}
if ($q44a == -1){
$nadining = $nadining + 1;
}
if ($q45a == -1){
$nadining = $nadining + 1;
}
if ($q78a == -1){
$naproduct = $naproduct + 1;
}
if ($q81a == -1){
$naproduct = $naproduct + 1;
}
if ($q83a == -1){
$napayment = $napayment + 1;
}
$arrival_na1 = $naarrival;
$arrival_ppna1 = 14 - $arrival_na1;
$totalarrival = $q11a + $q12a + $q13a + $q14a + $q15a + $q16a + $q17a + $q18a;
$arrival_score1 = $totalarrival / $arrival_ppna1 *100;
$dining_na1 = $nadining;
$dining_ppna1 = 31 - $dining_na1;
$totaldining = $q19a + $q20a + $q21a + $q22a + $q23a + $q24a + $q25a + $q26a + $q27a + $q28a + $q29a + $q30a + $q31a + $q32a + $q33a + $q34a + $q35a + $q36a + $q37a + $q38a + $q39a + $q40a + $q41a + $q42a + $q43a + $q44a + $q45a + $q46a + $q47a + $q48a + $q49a;
$dining_score1 = $totaldining / $dining_ppna1 *100;
$ordering_na1 = $naordering;
$ordering_ppna1 = 28 - $ordering_na1;
$totalordering = $q50a + $q51a + $q52a + $q53a + $q54a + $q55a + $q56a + $q57a;
$ordering_score1 = $totalordering / $ordering_ppna1 *100;
$product_na1 = $naproduct;
$product_ppna1 = 47 - $product_na1;
$totalproduct = $q58a + $q59a + $q60a + $q61a + $q62a + $q63a + $q64a + $q65a + $q66a + $q67a + $q68a + $q69a + $q70a + $q71a + $q72a + $q73a + $q74a + $q75a + $q76a + $q78a + $q78a1 + $q79a + $q79a1 + $q80a + $q81a;
$product_score1 = $totalproduct / $product_ppna1 *100;
$payment_na1 = $napayment;
$payment_ppna1 = 6 - $payment_na1;
$totalpayment = $q82a + $q83a + $q84a + $q85a;
$payment_score1 = $totalpayment / $payment_ppna1 *100;
$totalattentiveness1 = ($q16a + $q18a + $q51a + $q52a + $q55a + $q57a + $q85a) / 19 * 100;
$totalaccuracy1 = ($q50a + $q54a + $q56a) / 8 * 100;
$totalspeed1 = $q53a / 8 * 100;
$totalfriendliness1 = ($q17a + $q84a) / 6 * 100;
$totalpresentation1 = ($q63a + $q64a + $q67a + $q72a) / 5 * 100;
$totaltaste1 = ($q59a + $q61a + $q70a + $q71a + $q79a + $q80a) / 14 * 100;
$totalquality1 = ($q58a + $q60a + $q62a + $q65a + $q66a + $q68a + $q69a + $q73a + $q74a + $q75a + $q76a + $q78a + $q78a1 + $q79a1 + $q81a) / 28 * 100;
$total1 = $arrival_na1 + $dining_na1 + $ordering_na1 + $product_na1 + $payment_na1;
$total2 = $arrival_ppna1 + $dining_ppna1 + $ordering_ppna1 + $product_ppna1 + $payment_ppna1;
$total3 = $totalarrival + $totaldining + $totalordering + $totalproduct + $totalpayment;
$percentage = ($total3 / $total2) * 100;
if ($percentage >= 86) {
$grade = "A";
} else if ($percentage >= 70) {
$grade = "B";
} else if ($percentage >= 55) {
$grade = "C";
} else {
$grade = "D";
}
mysql_select_db("testing", $con) or die('Error:' .mysql_error());
$insert_query = "UPDATE a_team SET
date='$date',
q11a='$q11a',
q12a='$q12a',
q13a='$q13a',
q14a='$q14a',
q15a='$q15a',
q16a='$q16a',
q17a='$q17a',
q18a='$q18a',
q19a='$q19a',
q20a='$q20a',
q21a='$q21a',
q22a='$q22a',
q23a='$q23a',
q24a='$q24a',
q25a='$q25a',
q26a='$q26a',
q27a='$q27a',
q28a='$q28a',
q29a='$q29a',
q30a='$q30a',
q31a='$q31a',
q32a='$q32a',
q33a='$q33a',
q34a='$q34a',
q35a='$q35a',
q36a='$q36a',
q37a='$q37a',
q38a='$q38a',
q39a='$q39a',
q40a='$q40a',
q41a='$q41a',
q42a='$q42a',
q43a='$q43a',
q44a='$q44a',
q45a='$q45a',
q46a='$q46a',
q47a='$q47a',
q48a='$q48a',
q49a='$q49a',
q50a='$q50a',
q51a='$q51a',
q52a='$q52a',
q53a='$q53a',
q54a='$q54a',
q55a='$q55a',
q56a='$q56a',
q57a='$q57a',
q58a='$q58a',
q59a='$q59a',
q60a='$q60a',
q61a='$q61a',
q62a='$q62a',
q63a='$q63a',
q64a='$q64a',
q65a='$q65a',
q66a='$q66a',
q67a='$q67a',
q68a='$q68a',
q69a='$q69a',
q70a='$q70a',
q71a='$q71a',
q72a='$q72a',
q73a='$q73a',
q74a='$q74a',
q75a='$q75a',
q76a='$q76a',
q78a='$q78a',
q78a1='$q78a1',
q79a='$q79a',
q79a1='$q79a1',
q80a='$q80a',
q81a='$q81a',
q82a='$q82a',
q83a='$q83a',
q84a='$q84a',
q85a='$q85a',
totalarrival='$totalarrival',
arrival_score1='$arrival_score1',
totaldining='$totaldining',
dining_score1='$dining_score1',
totalordering='$totalordering',
ordering_score1='$ordering_score1',
totalproduct='$totalproduct',
product_score1='$product_score1',
totalpayment='$totalpayment',
payment_score1='$payment_score1',
totalattentiveness1='$totalattentiveness1',
totalaccuracy1='$totalaccuracy1',
totalspeed1='$totalspeed1',
totalfriendliness1='$totalfriendliness1',
totalpresentation1='$totalpresentation1',
totaltaste1='$totaltaste1',
totalquality1='$totalquality1',
timein='$timein',
HOR='$HOR',
MODa='$MODa',
KL='$KL',
ateambox='$ateambox',
box35='$box35',
box36='$box36',
box41='$box41',
box50='$box50',
box53='$box53',
box54='$box54',
box55='$box55',
box61a='$box61a',
box61aa='$box61aa',
box61b='$box61b',
box61bb='$box61bb',
box61c='$box61c',
box61cc='$box61cc',
box61d='$box61d',
box61dd='$box61dd',
box61e='$box61e',
box61ee='$box61ee',
box73a='$box73a',
box73b='$box73b',
box73c='$box73c',
box74a='$box74a',
box74b='$box74b',
box74c='$box74c',
box74d='$box74d',
box74e='$box74e',
box74f='$box74f',
box74g='$box74g',
box74h='$box74h',
box74i='$box74i',
box74j='$box74j',
box75a='$box75a',
box75b='$box75b',
box75c='$box75c',
box75d='$box75d',
box75e='$box75e',
box75f='$box75f',
box75g='$box75g',
box75h='$box75h',
box75i='$box75i',
box75j='$box75j',
box75k='$box75k',
box75l='$box75l',
box75m='$box75m',
box75n='$box75n',
box75o='$box75o',
box75p='$box75p',
box75q='$box75q',
box75r='$box75r',
box78a='$box78a',
box78b='$box78b',
box78c='$box78c',
box78d='$box78d',
box78e='$box78e',
box78f='$box78f',
box78g='$box78g',
box78h='$box78h',
box78i='$box78i',
box78j='$box78j',
box78k='$box78k',
box78l='$box78l',
box78m='$box78m',
box79a='$box79a',
box79b='$box79b',
box79c='$box79c',
box79d='$box79d',
box91a='$box91a',
box91b='$box91b',
box91c='$box91c',
box92a='$box92a',
box92b='$box92b',
arrival_na1='$arrival_na1',
arrival_ppna1='$arrival_ppna1',
dining_na1='$dining_na1',
dining_ppna1='$dining_ppna1',
ordering_na1='$ordering_na1',
ordering_ppna1='$ordering_ppna1',
product_na1='$product_na1',
product_ppna1='$product_ppna1',
payment_na1='$payment_na1',
payment_ppna1='$payment_ppna1',
total1='$total1',
total2='$total2',
total3='$total3',
percentage='$percentage',
grade='$grade' WHERE entry='$entry'";
mysql_query($insert_query) or die('Error:' . mysql_error());
mysql_close($con);
}
?>
Check whether you insert query give the correct query or not
echo $insert_qury="update query ";
and copy the output of insert query and test manually to past on sql in table it it update correctly then you query is correct and your error may be on "mysql_query"
You have put everything inside single quote...
Try this:
$insert_query = "UPDATE a_team SET
date='".$date."',
q11a='".$q11a."',
q12a='".$q12a."',..... WHERE entry='".$entry."'";

ajax php pagination wont show active page

I am working on a php ajax pagination.
The problem is that it wont ad the class="highlightActivePage" proper.
If I click on 1 - 2 - 3 , it works fine and highlight the number 3 if im on page 3.
But soon as I click on page 4 it highlights page 5 instead, etc.
Not sure if my for loop is wrong, but here us my code:
if (paginationHTML == "")
{
paginationHTML += "<ul>";
if (adResultsData.show_first_text == 1)
{
paginationHTML += "<li><a href='#' onclick='fetchResults(1);'>First</a></li>";
}
if (adResultsData.show_previous_text == 1)
{
paginationHTML += "<li><a href='#' onclick='fetchResults(" + (adResultsData.current_page - 1) + ");'>Prev</a></li>";
}
for (var i = 0; i < adResultsData.pages.length; i++)
{
if (adResultsData.current_page == (i + 1))
{
paginationHTML += "<li><a href='#' class='highlightActivePage' onclick='fetchResults(" + adResultsData.pages[i] + ");'>" + adResultsData.pages[i] + "</a></li>";
}
else
{
paginationHTML += "<li><a href='#' onclick='fetchResults(" + adResultsData.pages[i] + ");'>" + adResultsData.pages[i] + "</a></li>";
}
}
if (adResultsData.show_next_text == 1)
{
paginationHTML += "<li><a href='#' onclick='fetchResults(" + (adResultsData.current_page + 1) + ");'>Next</a></li>";
}
if (adResultsData.show_last_text == 1)
{
paginationHTML += "<li><a href='#' onclick='fetchResults(" + adResultsData.number_of_pages + ");'>last</a></li>";
}
paginationHTML += "</ul>";
paginationHTML += pageSpan.innerHTML = "<br>Page " + adResultsData.current_page + " of " + adResultsData.number_of_pages;
}
php
$numberOfPages = $results['pages'];
$currentPage = $results['currentPage'];
if ($currentPage != 1 && $currentPage != 2)
{$showFirst = 1;}
else $showFirst = 0;
if ($currentPage != 1)
{$showPrevious = 1;}
else $showPrevious = 0;
if ($currentPage != $numberOfPages)
{$showNext = 1;}
else $showNext = 0;
if ($currentPage != $numberOfPages && $currentPage != ($numberOfPages - 1))
{$showLast = 1;}
else $showLast = 0;
if ($currentPage <= 5 && $numberOfPages <= 5 || $numberOfPages <= 5)
{$startingPage = 1;}
else if ($currentPage == 1 || $currentPage == 2)
{$startingPage = 1;}
else
{$startingPage = $currentPage - 2;}
$pageNumbers = [];
for ($i = $startingPage; $i < ($startingPage + 5) && $i <= $numberOfPages; $i++)
{
$pageNumbers[] = $i;
}
$pagesString = implode(", ", $pageNumbers);
$listingsString = implode(", ", $listingsArray);
$jsonString = <<< END
{
"resultsTotal" : $numberOfResults,
"listings" : [$listingsString],
"number_of_pages" : $numberOfPages,
"current_page" : $currentPage,
Thanks!

Converting a hexadecimal string into binary in Objective-C

What's an equivalent of the PHP function pack:
pack('H*', '01234567989abcdef' );
in Objective-C?
Assuming that you want the results as an NSData, you can use a function similar to this:
NSData *CreateDataWithHexString(NSString *inputString)
{
NSUInteger inLength = [inputString length];
unichar *inCharacters = alloca(sizeof(unichar) * inLength);
[inputString getCharacters:inCharacters range:NSMakeRange(0, inLength)];
UInt8 *outBytes = malloc(sizeof(UInt8) * ((inLength / 2) + 1));
NSInteger i, o = 0;
UInt8 outByte = 0;
for (i = 0; i < inLength; i++) {
UInt8 c = inCharacters[i];
SInt8 value = -1;
if (c >= '0' && c <= '9') value = (c - '0');
else if (c >= 'A' && c <= 'F') value = 10 + (c - 'A');
else if (c >= 'a' && c <= 'f') value = 10 + (c - 'a');
if (value >= 0) {
if (i % 2 == 1) {
outBytes[o++] = (outByte << 4) | value;
outByte = 0;
} else if (i == (inLength - 1)) {
outBytes[o++] = value << 4;
} else {
outByte = value;
}
} else {
if (o != 0) break;
}
}
return [[NSData alloc] initWithBytesNoCopy:outBytes length:o freeWhenDone:YES];
}
See the -scanHex... methods of NSScanner.

Categories