PHP - Make This Faster More Efficient Anyway?
$ch = curl_init(); //////////////////////////////////// //////////////////////////////////// for($cwb=1; $cwb!=$Amount; $cwb++) { $action = file_get_contents($Game."refresh_stat_manual?user_id=".$Keys[0]."&auth_key=".$Keys[1]); $xml = simplexml_load_string($action); foreach($xml->xml->viewer->user as $stats) { $energy=$stats->energy; $level=$stats->level; } if($energy <= 0 || $Stop <= $level) { echo "REACHED EITHER LEVEL $Stop OR... YOU ARE OUT OF ENERGY...\n"; sleep(100000); } $send1 = $Game."send_requests?user_id=".$IDone."&to_user_ids=".$Keys[0]."&auth_key=".$AuthOne; curl_setopt($ch, CURLOPT_URL, $send1); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $send2 = $Game."send_requests?user_id=".$IDtwo."&to_user_ids=".$Keys[0]."&auth_key=".$AuthTwo; curl_setopt($ch, CURLOPT_URL, $send2); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $accept = $Game."accept_all_mob_requests?user_id=".$Keys[0]."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $accept); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $job = $Game."do_job?user_id=".$Keys[0]."&job_id=7200018&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $job); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $exec1 = curl_exec($ch); if(stristr($exec1, 'You gained 6') || stristr($exec1, 'You gained 1') || stristr($exec1, 'ambulance')) { echo "#$cwb: <-- You've gained 1 ambulance... Level - ".$level." ::: ENERGY - ".$energy." :::\n"; } for($abc =1; $abc!=2; $abc++){ $remove1 = $Game."remove_mob_member?user_id=".$Keys[0]."&remove_user_id=".$IDone."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $remove1); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);} for($abc =1; $abc!=2; $abc++){ $remove2 = $Game."remove_mob_member?user_id=".$Keys[0]."&remove_user_id=".$IDtwo."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $remove2); curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);} $sell = $Game."buy_item?user_id=".$Keys[0]."&item_id=32&amount=".$Amount."&auth_key=".$Keys[1]; curl_setopt($ch, CURLOPT_URL, $sell); $exec2 = curl_exec($ch); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if(stristr($exec2, 'sold')) { echo "::: You've sold 1 ambulance...\n"; } } curl_close(); Any idea on how I could make this faster or what I could change to make it to more efficient Similar TutorialsI have some code which i think is really inefficient especially as there will be more more conditions to be met. I was thinking about using s switch but don't know if this is possible or if it's best leaving as it is. Any ideas? if($parts[($i-1)]=="forum") { //do some code } else if($parts[($i-2)]=="forum") { //do code } else if (($parts[($i-1)]=="list-messages") && (isset($parts[($i+1)]))) { //do code } else { // do some code } Code: [Select] <?php $IPaddress = $_SERVER['REMOTE_ADDR']; if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) { echo "<center><b><i>CWB permits you to views this page...</i></b></center></br>"; echo '<center><b><font size="5">'.$IPaddress.'</font></b></center>'; } else { echo "<center><b>CWB DOES NOT PERMIT YOU TO VIEW THIS PAGE</b></center>"; } exit; ?> how do I make it to where I dont have to keep adding on to Code: [Select] if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) Okay so i have an image gallery script that creates two links, "Next Image" and "Previous Image". The script works but i'd like to know if i could make it more efficent with a better SQL query. Here's my database What i am currently doing is querying the database and getting a list of all the image id's in the same gallery, and putting them into an array. Which doesn't seem very logical (but it's the only solution i could come up with). Code: [Select] // CREATE AN ARRAY WITH ALL THE IMAGE ID'S IN THE GALLERY // $query = ("SELECT id FROM images WHERE gallery_id=(SELECT gallery_id FROM images WHERE id='".$_REQUEST['id']."') ORDER BY id DESC"); $result = mysql_query($query); $images_in_gallery = array(); while ($row = mysql_fetch_array($result)) { array_push($images_in_gallery, $row['id']); } And then searching through said the array to get the id of the next image and the previous image. Code: [Select] // CREATE THE LINK // $next_link = "<a href=\"?id=".$images_in_gallery[array_search($_REQUEST['id'], $images_in_gallery)+1]."\">$next_text</a>"; $prev_link = "<a href=\"?id=".$images_in_gallery[array_search($_REQUEST['id'], $images_in_gallery)-1]."\">$prev_text</a>"; Is there a way i can do this easier with a better query, for example a query that selects the next image in the gallery and the previous, i am not brilliant with SQL but i do know that if you have a good query your code can be considerably shorter. The full code can be found here on pastebin. http://pastebin.com/GzTpq6Uj I apologize for the length of my script. Is there a better way to do some of what I am doing here? My script is working fine but it works off a lot of data and if I try to query all the results, the response is pretty slow (1500ms). I'm concerned about that length of time when it comes to multiple users hitting the server at once. I may have to limit the query with pagination, etc. But, I just have a feeling there's a better way to do what I'm doing without over 1,000 lines....
//fetch production data if( $action == 'fetch_production_data' ) { //setup query $sql = 'SELECT * FROM production_data ORDER BY enterprise, job_number, TRIM(line_item) ASC'; //execute SQL transaction try { //prepare SQL statement & execute $stmt = $pdo->prepare($sql); $stmt->execute(); //bind column names to variables $stmt->bindColumn('id', $id); $stmt->bindColumn('job_number', $job_number); $stmt->bindColumn('enterprise', $enterprise); $stmt->bindColumn('part_number', $part_number); $stmt->bindColumn('description', $description); $stmt->bindColumn('qty', $qty); $stmt->bindColumn('line_item', $line_item); $stmt->bindColumn('as400_ship_date', $as400_ship_date); $stmt->bindColumn('date_showed_on_report', $date_showed_on_report); $stmt->bindColumn('shipping_method', $shipping_method); $stmt->bindColumn('notes', $notes); $stmt->bindColumn('date_shown_complete', $date_shown_complete); $stmt->bindColumn('actual_ship_date', $actual_ship_date); $stmt->bindColumn('qty_shipped', $qty_shipped); //store user dept code $user_dept_code = get_user_dept( $_SESSION[ 'user_id' ], $pdo ); //$button = ''; //output data into spreadsheet view while($row = $stmt->fetch(PDO::FETCH_BOUND)) { //setup vars to store button HTML $btn_qc = ''; $btn_thermoforming = ''; $btn_vinylpaint = ''; $btn_finalassm = ''; $btn_crateship = ''; //store each dept status query for performance $status_qc = isset( get_order_status( $id, 10, $pdo )[0]['status_id'] ) ? get_order_status( $id, 10, $pdo )[0]['status_id'] : '0'; $status_thermoforming = isset( get_order_status( $id, 6, $pdo )[0]['status_id'] ) ? get_order_status( $id, 6, $pdo )[0]['status_id'] : '0'; $status_vinylpaint = isset( get_order_status( $id, 5, $pdo )[0]['status_id'] ) ? get_order_status( $id, 5, $pdo )[0]['status_id'] : '0'; $status_finalassm = isset( get_order_status( $id, 7, $pdo )[0]['status_id'] ) ? get_order_status( $id, 7, $pdo )[0]['status_id'] : '0'; $status_crateship = isset( get_order_status( $id, 8, $pdo )[0]['status_id'] ) ? get_order_status( $id, 8, $pdo )[0]['status_id'] : '0'; $status_msg = 'Order ' . $id .' '; //echo $status_vinylpaint . '<br>'; //build view based on user's department code switch ( $user_dept_code ) { //Design or AMS View case '4': case '9': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Not Started</button>'; break; } //determine status of order thermoforming switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Not Started</button>'; break; } //determine status of order for vinyl & paint switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Not Started</button>'; break; } //determine status of order final assembly switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Not Started</button>'; break; } //determine status of order for crating & shipping switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Not Started</button>'; break; } //break parent switch break; //Vinyl & Paint View case '5': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Not Started</button>'; break; } //determine status of order thermoforming switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Not Started</button>'; break; } //determine status of order for vinyl & paint switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5">In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5">Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5">Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5">Not Started</button>'; break; } //determine status of order final assembly switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Not Started</button>'; break; } //determine status of order for crating & shipping switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Not Started</button>'; break; } //break parent switch break; //Thermoforming View case '6': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Not Started</button>'; break; } //determine status of order thermoforming switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6">In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6">Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6">Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6">Not Started</button>'; break; } //determine status of order for vinyl & paint switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Not Started</button>'; break; } //determine status of order final assembly switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Not Started</button>'; break; } //determine status of order for crating & shipping switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Not Started</button>'; break; } //break parent switch break; //Derrick Donnel's View case '7,8': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Not Started</button>'; break; } //determine status of order for qc dept switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Not Started</button>'; break; } //determine status of order for qc dept switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Not Started</button>'; break; } //determine status of order for qc dept switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">Not Started</button>'; break; } //determine status of order for qc dept switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">Not Started</button>'; break; } //break parent switch break; //Final Assembly View case '7': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Not Started</button>'; break; } //determine status of order thermoforming switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Not Started</button>'; break; } //determine status of order for vinyl & paint switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Not Started</button>'; break; } //determine status of order final assembly switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7">Not Started</button>'; break; } //determine status of order for crating & shipping switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Not Started</button>'; break; } //break parent switch break; //Crating & Shipping View' case '8': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10" disabled>Not Started</button>'; break; } //determine status of order thermoforming switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Not Started</button>'; break; } //determine status of order for vinyl & paint switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Not Started</button>'; break; } //determine status of order final assembly switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Not Started</button>'; break; } //determine status of order for crating & shipping switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8">Not Started</button>'; break; } //break parent switch break; //Quality Control View' case '10': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10">In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10">Delayed</button>'; break; //order finished case '3': $btn_qc = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10">Finished</button>'; break; //order not started case '0': default: $btn_qc = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10">Not Started</button>'; break; } //determine status of order thermoforming switch ( $status_thermoforming ) { //order in progress case '1': $btn_thermoforming = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>In Progress</button>'; break; //order delayed case '2': $btn_thermoforming = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Delayed</button>'; break; //order finished case '3': $btn_thermoforming = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Finished</button>'; break; //order not started case '0': default: $btn_thermoforming = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="6" disabled>Not Started</button>'; break; } //determine status of order for vinyl & paint switch ( $status_vinylpaint ) { //order in progress case '1': $btn_vinylpaint = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>In Progress</button>'; break; //order delayed case '2': $btn_vinylpaint = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Delayed</button>'; break; //order finished case '3': $btn_vinylpaint = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Finished</button>'; break; //order not started case '0': default: $btn_vinylpaint = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="5" disabled>Not Started</button>'; break; } //determine status of order final assembly switch ( $status_finalassm ) { //order in progress case '1': $btn_finalassm = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>In Progress</button>'; break; //order delayed case '2': $btn_finalassm = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Delayed</button>'; break; //order finished case '3': $btn_finalassm = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Finished</button>'; break; //order not started case '0': default: $btn_finalassm = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="7" disabled>Not Started</button>'; break; } //determine status of order for crating & shipping switch ( $status_crateship ) { case '1': $btn_crateship = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>In Progress</button>'; break; //order delayed case '2': $btn_crateship = '<button type="button" class="btn btn-danger btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Delayed</button>'; break; //order finished case '3': $btn_crateship = '<button type="button" class="btn-success btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Finished</button>'; break; //order not started case '0': default: $btn_crateship = '<button type="button" class="btn btn-secondary btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="8" disabled>Not Started</button>'; break; } //break parent switch break; //SU/Op. Mngt/Prod. Mngt View case '1': case '2': case '3': //determine status of order for qc dept switch ( $status_qc ) { //order in progress case '1': $btn_qc = '<button type="button" class="btn btn-warning btn-sm btn_change_order_status_dialog" style="margin:0; width: 100px; height:100%; font-weight: bold;" data-order-id="'. $id . '" data-order-number="'. $job_number . '" data-order-enterprise="'. $enterprise . '" data-dept-code="10">In Progress</button>'; break; //order delayed case '2': $btn_qc = '<button type="button" cla I read the tutorial, "Handling XML Data" and created this script from it. Excellent tutorial by the way Here is my script: Code: [Select] <?php // load SimpleXML $fx = new SimpleXMLElement('http://www.boj.org.jm/uploads/fxrates.xml', null, true); echo '<table><tr class="fx_header"><th class="fx_date">'; echo $fx->US[0]->DATE; echo '</th><th class="fx_buy">Buy</th><th class="fx_sell">Sell</th></tr><tr class="fx_us"><td class="fx_legend">USD (&#36;)</td><td class="fx_buy_sell">&#36;'; echo $fx->US[0]->BUY; echo '</td><td class="fx_buy_sell">&#36;'; echo $fx->US[0]->SELL; echo '</td></tr><tr class="fx_cad"><td class="fx_legend">CAD (&#36;)</td><td class="fx_buy_sell">&#36;'; echo $fx->CAD[0]->BUY; echo '</td><td class="fx_buy_sell">&#36;'; echo $fx->CAD[0]->SELL; echo '</td></tr><tr class="fx_gbp"><td class="fx_legend">GBP (&#163;)</td><td class="fx_buy_sell">&#36;'; echo $fx->GBP[0]->BUY; echo '</td><td class="fx_buy_sell">&#36;'; echo $fx->GBP[0]->SELL; echo '</td></tr></table>'; ?> This is the XML file that the script is reading from: http://www.boj.org.jm/uploads/fxrates.xml This is the result page (which is just the way it should look): http://projects.wstudiographics.com/ewl/boj/fxrates.php It works very well, but it take a bit of time to return the result. I think it's because of how the XML file data was set up. The thing is that I have no control over the xml data. I am only allowed to read it. I only need the first or rather latest instance of the data. Any help on this will be greatly appreciated. Thanks in advanced. Winchester (WStudio) Hello, everyone: I'm using PHP and Mysql. I've got a table of that has 30 fields that I need to add together. I've got to do this for each record, and there are about 10,000 records. Which would be more efficient? SELECT SUM( field1 + field2...) or to make an array for the fields and then use array_sum() Thanks. I have a flow control statement that has to write "1+2+3+4...+100" and then display the total (5050) on the webpage. The current code that I have is Code: [Select] <html> <head><title>Adding Numbers Script</title></head> <body> <?php $num=0; $sum=0; while ($num<=99) { {$sum=$sum+$num++; echo "$num+ ";} } if ($num>99){$sum=$sum+$num; echo"$num= ";} echo "$sum"; ?> </body> </html> However, I was told that it could be made more efficient by only having one flow control statement in there, rather than the two I have at the moment (the while and the if statements). Can anyone help me make this more efficient? Thanks in advance, Andrew When I run this code it takes longer then I want to load the search results. I thought by only loading the first 30 rows it catches it would speed things up. Any ideas? I changed the $db to be 30, but only my first page painted and it was not much faster.... Code: [Select] if(!empty($keyword) && $keyword!='Zip Code') $sql="SELECT profiles.*,zipCode FROM profiles LEFT JOIN area_served ON area_served.profileId = profiles.profileId WHERE profileType!='HO' AND profiles.status='Y' $qrystr GROUP BY profiles.profileId $orderby CASE zipCode $zips_order_str , companyName asc "; else $sql="SELECT * FROM profiles LEFT JOIN area_served ON area_served.profileId = profiles.profileId WHERE profileType!='HO' and status='Y' $qrystr GROUP BY profiles.profileId $orderby "; //echo $sql; $db->query($sql); $numRows=$db->numRows(); $page->set_page_data($_SERVER[PHP_SELF],$numRows,$listing,10,true,false,true); $page->set_qry_string("searchFor=$searchFor&cat=$cat&state=$state&keyword=$keyword&distance=$distance&sorting=$sorting&listing=$listing"); $res=$db->query($page->get_limit_query($sql)); $smarty->assign('numResult',$numRows); /* show pagination */ while($row=$db->fetchAssoc($res)) { if($row['thumbnailPhoto']=='personalPhoto' || $row['thumbnailPhoto']==''){ if(!empty($row['personalPhoto'])){ $personalPhoto="profiles/".$row['personalPhoto']; $rimg->setImage($personalPhoto); $row['personalPhoto']=$rimg->resize(75,75,substr($personalPhoto,0,strpos($personalPhoto,"."))."_search"); }else{ $row['personalPhoto']="images/my-photo.gif"; } }else{ if(!empty($row['logo'])){ $personalPhoto="profiles/".$row['logo']; $rimg->setImage($personalPhoto); $row['personalPhoto']=$rimg->resize(75,75,substr($personalPhoto,0,strpos($personalPhoto,"."))."_search"); }else{ $row['personalPhoto']="images/my-photo.gif"; } } if(count($cat>0)){ $row['cat']=@implode(", ",$cat); } if(strlen($row['companyInfo'])>90){ $concat="..."; } else{ $concat=""; } my code: Code: [Select] echo $Profile['display']; ECHO's out: 0|1|0|1 Now I want to explode these, which is easy Code: [Select] $display = explode("|", $Profile['display']); But Now I want to use a php function to check if any of the array's = "1" and have the value set to $value= "checked"; I could do this by doing Code: [Select] if ($display['0'] == "1"){ $value = "checked"; } and then 1 2 3 and so on.. but I want a faster way, maybe a for loop, or a simpliar easier way to just check if each array = 1, make $value = checked Possible right? this is my script it gets the values form the database and adds them and saves it to a variable which is then echoed to the user before i typed this code 10 more times changing every variable name i was wondering if their was a more efficient way of doing this Code: [Select] <?php $adam_view_query = "SELECT * FROM pinkpanther_stats WHERE Player = 'Adam' ORDER BY Day_Played DESC"; $adam_view_results = mysql_query($adam_view_query) or die("Query failed ($adam_view_query) - " . mysql_error()); $adam_view_numrows = mysql_num_rows($adam_view_results); $adam_gli_query = "SELECT SUM(GLI) AS 'adam_gli' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_gli_results = mysql_query($adam_gli_query) or die ("Query failed ($adam_gli_query) - " . mysql_error()); $adam_gli_row = mysql_fetch_array($adam_gli_results); $adam_gli = $adam_gli_row['adam_gli']; $adam_goals_query = "SELECT SUM(Goals) AS 'adam_goals' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_goals_results = mysql_query($adam_goals_query) or die ("Query failed ($adam_goals_query) - " . mysql_error()); $adam_goals_row = mysql_fetch_array($adam_goals_results); $adam_goals = $adam_goals_row['adam_goals']; $adam_saves_query = "SELECT SUM(Saves) AS 'adam_saves' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_saves_results = mysql_query($adam_saves_query) or die ("Query failed ($adam_saves_query) - " . mysql_error()); $adam_saves_row = mysql_fetch_array($adam_saves_results); $adam_saves = $adam_saves_row['adam_saves']; $adam_sog_query = "SELECT SUM(SOG) AS 'adam_sog' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_sog_results = mysql_query($adam_sog_query) or die ("Query failed ($adam_sog_query) - " . mysql_error()); $adam_sog_row = mysql_fetch_array($adam_sog_results); $adam_sog = $adam_sog_row['adam_sog']; $adam_assists_query = "SELECT SUM(Assists) AS 'adam_assists' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_assists_results = mysql_query($adam_assists_query) or die ("Query failed ($adam_assists_query) - " . mysql_error()); $adam_assists_row = mysql_fetch_array($adam_assists_results); $adam_assists = $adam_assists_row['adam_assists']; $adam_ck_query = "SELECT SUM(CK) AS 'adam_ck' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_ck_results = mysql_query($adam_ck_query) or die ("Query failed ($adam_ck_query) - " . mysql_error()); $adam_ck_row = mysql_fetch_array($adam_ck_results); $adam_ck = $adam_ck_row['adam_ck']; $adam_yc_query = "SELECT SUM(YC) AS 'adam_yc' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_yc_results = mysql_query($adam_yc_query) or die ("Query failed ($adam_yc_query) - " . mysql_error()); $adam_yc_row = mysql_fetch_array($adam_yc_results); $adam_yc = $adam_yc_row['adam_yc']; $adam_rc_query = "SELECT SUM(RC) AS 'adam_rc' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_rc_results = mysql_query($adam_rc_query) or die ("Query failed ($adam_rc_query) - " . mysql_error()); $adam_rc_row = mysql_fetch_array($adam_rc_results); $adam_rc = $adam_rc_row['adam_rc']; $adam_goalie = ""; if (isset($_POST['adam_go'])) { $adam_view = mysql_real_escape_string($_POST['adam_statview']); if ($adam_view == "Total"){ $adam_gli_query = "SELECT SUM(GLI) AS 'adam_gli' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_gli_results = mysql_query($adam_gli_query) or die ("Query failed ($adam_gli_query) - " . mysql_error()); $adam_gli_row = mysql_fetch_array($adam_gli_results); $adam_gli = $adam_gli_row['adam_gli']; $adam_goals_query = "SELECT SUM(Goals) AS 'adam_goals' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_goals_results = mysql_query($adam_goals_query) or die ("Query failed ($adam_goals_query) - " . mysql_error()); $adam_goals_row = mysql_fetch_array($adam_goals_results); $adam_goals = $adam_goals_row['adam_goals']; $adam_saves_query = "SELECT SUM(Saves) AS 'adam_saves' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_saves_results = mysql_query($adam_saves_query) or die ("Query failed ($adam_saves_query) - " . mysql_error()); $adam_saves_row = mysql_fetch_array($adam_saves_results); $adam_saves = $adam_saves_row['adam_saves']; $adam_sog_query = "SELECT SUM(SOG) AS 'adam_sog' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_sog_results = mysql_query($adam_sog_query) or die ("Query failed ($adam_sog_query) - " . mysql_error()); $adam_sog_row = mysql_fetch_array($adam_sog_results); $adam_sog = $adam_sog_row['adam_sog']; $adam_assists_query = "SELECT SUM(Assists) AS 'adam_assists' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_assists_results = mysql_query($adam_assists_query) or die ("Query failed ($adam_assists_query) - " . mysql_error()); $adam_assists_row = mysql_fetch_array($adam_assists_results); $adam_assists = $adam_assists_row['adam_assists']; $adam_ck_query = "SELECT SUM(CK) AS 'adam_ck' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_ck_results = mysql_query($adam_ck_query) or die ("Query failed ($adam_ck_query) - " . mysql_error()); $adam_ck_row = mysql_fetch_array($adam_ck_results); $adam_ck = $adam_ck_row['adam_ck']; $adam_yc_query = "SELECT SUM(YC) AS 'adam_yc' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_yc_results = mysql_query($adam_yc_query) or die ("Query failed ($adam_yc_query) - " . mysql_error()); $adam_yc_row = mysql_fetch_array($adam_yc_results); $adam_yc = $adam_yc_row['adam_yc']; $adam_rc_query = "SELECT SUM(RC) AS 'adam_rc' FROM pinkpanther_stats WHERE Player = 'Adam'"; $adam_rc_results = mysql_query($adam_rc_query) or die ("Query failed ($adam_rc_query) - " . mysql_error()); $adam_rc_row = mysql_fetch_array($adam_rc_results); $adam_rc = $adam_rc_row['adam_rc']; $adam_goalie = ""; }else{ $adam_stats_query = "SELECT * FROM pinkpanther_stats WHERE Player = 'Adam' AND Day_Played = '$adam_view'"; $adam_stats_results = mysql_query($adam_stats_query) or die ("Query failed ($adam_stats_query) - " . mysql_error()); $adam_stats_row = mysql_fetch_array($adam_stats_results); $adam_goalie_test = $adam_stats_row['Goalie']; $adam_gli = $adam_stats_row['GLI']; $adam_goals = $adam_stats_row['Goals']; $adam_saves = $adam_stats_row['Saves']; $adam_sog = $adam_stats_row['SOG']; $adam_assists = $adam_stats_row['Assists']; $adam_ck = $adam_stats_row['CK']; $adam_yc = $adam_stats_row['YC']; $adam_rc = $adam_stats_row['RC']; if ($adam_goalie_test == 1){ $adam_goalie = "Yes"; }else{ $adam_goalie = "No"; } } } ?> Hi all I wonder if you could give me some advice. I basically have a mysql database of staff who work at a college, I have a front which displays details of a staff member, I grab the details using userdetails.php?id=44 (44 being the ID of the staff member) One field I have in my MySQL database is "title", which is basically Mr Ms Mrs Miss Dr At the moment, I store the "title" value in the database as "CHAR", so it appears as "Mrs" for example when I print print $row['title']; What I want to know is, which is the best method of storing and getting this data. Is it best to ----------------------------------------------------- 1: Continue as I am and keep text values in the database stored as CHAR[/li][/list] ----------------------------------------------------- 2: Change it so that instead of storing "Mr", "Dr" as CHAR, I would store them as numeric values, so; 2 would be Mr 3 would be Mrs 4 would be Dr then do a if($row['title'] == 2) { print "Mr"; } elseif($row['title'] == 3) { print "Mrs"; } elseif($row['title'] == 4) { print "Dr"; } ----------------------------------------------------- 3: Change it so that instead of storing "Mr", "Dr" as CHAR, I would store them as numeric values, but then have another database table which holds what value each number is, so my new database table would be like --- title_values ---- id value 2 Mr 3 Mrs 4 Dr ------------------------- then on the front end, do a SELECT such as SELECT `value` FROM `title_values` WHERE `id` = "'.$row['id'].'" I guess the advantage to this one, is that I can modify the list of titles and expand it. ----------------------------------------------------- which of those is generally considered better? faster? and less server intensive? or is there a better way to do it? Thanks very much Say I have a MySQL table with two fields: "id" (primary key, INT(7)) and "hash" (indexed, VARCHAR(32)), and there will be hundreds of thousands of records in this table. Would it be faster / less CPU intensive to use MySQL to match both the id and hash fields to cleaned / sanitized request vars, or just match the id field with MySQL, and then use PHP to determine whether or not the hash is correct? So, mysql_query("SELECT * FROM table WHERE id='" .$id. "' AND hash=' .$hash. '"); or: $query = mysql_query("SELECT * FROM table WHERE id='" .$id. "'"); $row = mysql_fetch_assoc($query); if ($row['hash'] == $hash) .. One scenario you're requiring MySQL to match two things (the hash field would be 32 characters long, like a md5 string), the other way it would only have to find one field (a unique, primary key integer, which should be very fast), but MySQL would need to pull the data and put into an array that PHP can then read to determine if the other field is a match. I'm thinking the all-MySQL way would be faster, but I didn't know about it having to search through hundreds of thousands of records for a string of that size. Any thoughts? Thanks! I have a 5000 item array of grocery UPC numbers and prices (here's a snippet):
$myarray = array(
'3540132662329' => '74.46',
'8870132664186' => '63.24', $HEADER = "http://www.google.com"; for($cwb=1; $cwb!=100; $cwb++) { $repeat = file_get_contents($HEADER); $msg = explode('<message>', $repeat); $msg = explode('</', $msg[1]); echo "#$cwb: ".$msg[0]."\n"; } why is this much faster? $HEADER = "http://www.google.com"; $REPEAT = 100; // times to repeat $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); for($cwb=1; $cwb!=$REPEAT; $cwb++) { curl_setopt($ch, CURLOPT_URL, $HEADER); $msg = explode('<message>', curl_exec($ch)); $msg = explode('</', $msg[1]); echo "#$cwb: ".$msg[0]."\n"; } while($ch); curl_close($ch); is there anything faster than both of these options? this xml_parse_into_struct($iP=xml_parser_create(), curl_exec($ch), $bR, $bJ);xml_parser_free($iP); echo "::: ".strip_tags(str_replace("<br>","\n",$bR[$bJ['MESSAGE'][0]]['value']))."\n"; or... $xml = simplexml_load_string(curl_exec($ch)); foreach($xml->xml as $message){ echo strip_tags($message->message)."\n";} Just want to know which of these two would execute faster and if there was a better way that would be faster than both of these options? Thanks i need this code to execute faster, is there a faster way? function all_word_combinations($all_words_unknown,$previous_string=''){ $all_words_2=array(); if(is_array($all_words_unknown)){ $all_words_array=$all_words_unknown; }else{ $all_words_array=explode(' ',trim($all_words_unknown)); } $item2remove='the'; $all_words_array=explode(' ',trim(str_replace($item2remove.' ','',str_replace(' '.$item2remove,'',(implode(' ',$all_words_array)))))); if(count($all_words_array)>1){ $previous_array=explode(' ',$previous_string); foreach($all_words_array as $one_word){ if(!in_array($previous_string.$one_word,$all_words_2) && !in_array($one_word,$previous_array)){ $all_words_2[$previous_string.$one_word]=$previous_string.$one_word; $all_words_2=array_merge($all_words_2,all_word_combinations($all_words_array,$previous_string.$one_word.' ')); } } return $all_words_2; }else{return $all_words_array;} } $one_word_combination=''; foreach(all_word_combinations('cat dog mouse turtle shark whale elephant giraffe lion tiger fish monkey') as $one_word_combination){echo str_replace(' ','-',$one_word_combination).'<br />';} Hi guys, I want to find the most efficient way of setting a php variable through a link.
What I'm trying to achieve is to allow the user to select a category and their location and store the two variables to update my database results. I first used the GET method, but since the page refreshes when the user selects any other Get variable, so it ends up reseting the variables. Currently I have the category and locations as drop down menu with links to each of the options. I'll appreciate any help. Thank you. :]
Hi all, I've been trying to improve the speed of my file download script and was wondering if anyone could advise me which of the following is more efficient (Don't worry its not the whole script, just one segment), in terms of speed and server load? The way I have the segment currently: //if file exists need to check authorision levels //set access to no $access = NULL; //retrieve current user levels $cpm = $_SESSION['MM_CPMGroup']; $cpmh = $_SESSION['MM_CPMHGroup']; $cm = $_SESSION['MM_CMGroup']; $cj200 = $_SESSION['MM_CJ200Group']; $cj = $_SESSION['MM_CJGroup']; //set file category type & set access if allowed if ($category == 'cpm') { if ($cpm == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cpm/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cpm/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cpm/"; } else { $path = "files/cpm/"; } } } elseif ($category == 'cpmh') { if ($cpmh == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cpmh/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cpmh/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cpmh/"; } else { $path = "files/cpmh/"; } } } elseif ($category == 'cm') { if ($cm == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cm/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cm/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cm/"; } else { $path = "files/cm/"; } } } elseif ($category == 'cj200') { if ($cj200 == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cj200/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cj200/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cj200/"; } else { $path = "files/cj200/"; } } } elseif ($category == 'cj') { if ($cj == '1') { $access = 1; if ($subcategory == 'techdata') { $path = "files/techdata/cj/"; } elseif ($subcategory == 'msds') { $path = "files/techdata/cj/msds/"; } elseif ($subcategory == 'symbols') { $path = "files/symbols/cj/"; } else { $path = "files/cj/"; } } } if ($access < 1) { // if user access not granted to file category return message if($logging > 0){ $status = "Wrong Permissions"; include('logit.php'); } if (! $_SESSION['PrevUrl']) { //header("Location: ". $loginpage ); exit; } $redirect = $_SESSION['PrevUrl']; header("Location: ". $redirect ); exit; } // if file exists and user access granted continue Obviously the above is a lot of lines of code... So I have rewritten the above to look like: //if file exists need to check authorision levels & retrieve current user levels if ($category == 'cpm' && $_SESSION['MM_CPMGroup'] == '1') { $access = 1; } elseif ($category == 'cpmh' && $cpmh = $_SESSION['MM_CPMHGroup'] == '1') { $access = 1; } elseif ($category == 'cm' && $cm = $_SESSION['MM_CMGroup'] == '1') { $access = 1; } elseif ($category == 'cj200' && $_SESSION['MM_CJ200Group'] == '1') { $access = 1; } elseif ($category == 'cj' && $_SESSION['MM_CJGroup'] == '1') { $access = 1; } else { $access = NULL; } if ($access == NULL) { // if user access not granted to file category return message $status = "Unauthorised"; include('logit.php'); header("Location: ".$_SESSION['PrevUrl']); exit; } // if file exists and user access granted continue switch($subcategory) { case "techdata":$path="files/techdata/".$category."/".$filename; break; case "msds": $path="files/techdata/".$category."/msds/".$filename; break; case "symbols": $path="files/symbols/".$category."/".$filename; break; default: $path="files/".$category."/".$filename; } The second version is a lot shorter, but is it better? And could I shorten the if statement further so its more like: //if file exists need to check authorision levels & retrieve current user levels if (($category == 'cpm' && $_SESSION['MM_CPMGroup'] == '1') || ($category == 'cpmh' && $cpmh = $_SESSION['MM_CPMHGroup'] == '1') || ($category == 'cm' && $cm = $_SESSION['MM_CMGroup'] == '1') || ($category == 'cj200' && $_SESSION['MM_CJ200Group'] == '1') || ($category == 'cj' && $_SESSION['MM_CJGroup'] == '1') { $access = 1; } else { $access = NULL; } if ($access == NULL) { // if user access not granted to file category return message $status = "Unauthorised"; include('logit.php'); header("Location: ".$_SESSION['PrevUrl']); exit; } // if file exists and user access granted continue switch($subcategory) { case "techdata":$path="files/techdata/".$category."/".$filename; break; case "msds": $path="files/techdata/".$category."/msds/".$filename; break; case "symbols": $path="files/symbols/".$category."/".$filename; break; default: $path="files/".$category."/".$filename; } Any advice would be appreciated! Thanks!! This question includes MySQL, but I have a feeling the answer will involve PHP so putting it here for now. If it should be moved, feel free Say I have a for loop that iterates through a certain amount of times and updates a value in my database EACH ITERATION thru the loop. In other words, we're connecting to the database multiple times. Seems very inefficient, so I'd like to see if there is a better way. Here is a basic example of the "bad" way (FYI, this code is basically reordering items after one of them moves down in the list)... Code: [Select] for ($a=$oldvalue+1; $a<=$othervalue; $a++) { $sql = "UPDATE tablewithids SET id=id - 1 WHERE id=$a"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { } So if $othervalue happened to be 80, then it would be 80 separate connections to the database! I imagine it would make a lot more sense to gather the data first (into an array I presume) and then make one connection to the database an update that way, but I'm having trouble wrapping my head around how to do it based on this type of example. Can anyone offer suggestions to help make this type of for loop code more efficient? |