Jump to content

WStudio

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

WStudio's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Once again Gizmola, Thank you for your help. I started reconstruct it in javascript.. I had already started it before.. I guess I'm going to have to just finish it. Thanks Best regards, Winchester
  2. Thank you very much for your reply. The truth is, it wasn't apart of the design. It wasn't until later the client refused it because it wasn't doing what he wanted it to do. You know that type of client that keeps changing things during the development process. Luckly most of the new stuff were stuff I could add.. but I'm blank with this one. And this is the last thing I have to do the complete the project. What do you propose I do to get this done?
  3. According to what phpMyAdmin is saying you're viewing 0 to 0 and you have 1 total record. If you had 5 records total in your table, it would show 0 - 4 (5 Total.... ). If you have 100 and you're looking at page 2 (with the default pagination) it would show 31 - 60 ( 100 Total... ). If that's the only record in the table, then phpMyAdmin is correct and it may be your php script. But if you have more than only 1 record in your table, then you may be correct.
  4. Hi, I've been working on this shipment calculator script for some time now. It's works fine as it is except for one thing. I have been trying to figure out how to get the script to calculate the freight cost from just the weight or volume (length, width & height) fields. The way that it is now is that you have to enter a product cost and quantity for it to calculate anything. Some people just want the freight charges and nothing else. The classes: I know it's not very tidy, but I plan on cleaning it up once I get it working properly. <?php class ShippingCalculator { // Defaults var $postUrl; var $settings; var $weight = 1; var $weight_unit = "lb"; var $size_length = 4; var $size_width = 8; var $size_height = 2; var $size_unit = "in"; var $debug = false; // Change to true to see XML sent and recieved var $tax; var $minInsurance; var $brokerageFee; var $weightRates; var $volumeRates; var $volume; function ShippingCalculator(){ global $settings; $this->tax = 17.5; $this->minInsurance = 15.00; $this->brokerageFee = 10.00; $this->postUrl = $settings['siteurl_content'].'ajax.php'; } // Convert Weight function convert_weight($weight,$old_unit,$new_unit) { $units['oz'] = 1; $units['lb'] = 0.0625; $units['gram'] = 28.3495231; $units['kg'] = 0.0283495231; // Convert to Ounces (if not already) if($old_unit != "oz") $weight = $weight / $units[$old_unit]; // Convert to New Unit $weight = $weight * $units[$new_unit]; // Minimum Weight if($weight < .1) $weight = .1; // Return New Weight return round($weight,2); } // Convert Size function convert_size($size,$old_unit,$new_unit) { $units['in'] = 1; $units['cm'] = 2.54; $units['feet'] = 0.083333; // Convert to Inches (if not already) if($old_unit != "in") $size = $size / $units[$old_unit]; // Convert to New Unit $size = $size * $units[$new_unit]; // Minimum Size if($size < .1) $size = .1; // Return New Size return round($size,2); } // Weight Rates function getWeightRate($weight){ if($weight <= 6 ){ $rate = 25.00; $wTotal = $rate; }elseif($weight > 6 && $weight <= 24 ){ $rate = 4.00; $wTotal = $weight * $rate; }elseif($weight > 24 && $weight <= 100){ $rate = 3.50; $wTotal = $weight * $rate; }elseif($weight > 100){ $rate = 3.00; $wTotal = $weight * $rate; } return $wTotal; } // Calculate volume of item // Since measurements are going to be entered in inches, we have to convert it into cubic feet. function totalVolume($length, $width, $height){ $cubicft = 1728; // 1 cubic foot = inches (12x12x12) $involume = $length * $width * $height; // Volume calculated in cubic inches $volume = $involume / $cubicft; // Converting cubic inches to cubic feet return $volume; } function calculateVolume($length, $width, $height){ $cubicft = 1728; // 1 cubic foot = inches (12x12x12) $involume = $length * $width * $height; // Volume calculated in cubic inches $volume = $involume / $cubicft; // Converting cubic inches to cubic feet return $volume; } // Volume Rates function getVolumeRate($volume){ if($volume <= 2 ){ $rate = 15.00; $vTotal = $rate; }elseif($volume > 2 && $volume <= 40){ $rate = 8.00; $vTotal = $volume * $rate; }elseif($volume > 40 && $volume <= 60){ $rate = 7.00; $vTotal = $volume * $rate; }elseif($volume > 60 && $volume <= 100){ $rate = 6.00; $vTotal = $volume * $rate; }elseif($volume > 100){ $rate = 5.00; $vTotal = $volume * $rate; } return $vTotal; } function totalProductCost($product, $shipping, $qty){ $results = array(); if(isset($_POST['insurance']) == 'true'){ $tenpercent = (10 / 100); // Turn 10% into .10. $onepercent = (1.1 / 100); // Turn 1.1% into .1. $productCost = $product * $qty; $total = $productCost + $shipping; $insuranceA = $productCost * $tenpercent; // Insurance A - 10% of Product Cost $insuranceB = $productCost + $insuranceA; // Insurance B - Adding the 10% of Product Cost back to the Product Cost $insurance = $insuranceB * $onepercent; // Insurance - Working out the 1.1% of the Product Cost plus the 10% if($insurance <= $this->minInsurance){ $insuranceCost = number_format($this->minInsurance, 2); } elseif($insurance >= $this->minInsurance) { $insuranceCost = number_format($insurance, 2); } $Gtotal = $total + $insuranceCost + number_format($this->brokerageFee, 2); $results['grandtotal'] = number_format($Gtotal, 2); } else { $productCost = $product * $qty; $total = $productCost + $shipping; $Gtotal = $total + $this->brokerageFee; $results['grandtotal'] = number_format($Gtotal, 2); } $results['insurance'] = $insuranceCost; $results['subtotal'] = $total; $results['productcost'] = number_format($productCost, 2); $results['freightcost'] = number_format($shipping, 2); $results['brokeragefee'] = number_format($this->brokerageFee, 2); return $results; } function shippingCost($product, $shipping, $qty){ $results = array(); $productCost = $product * $qty; $total = $productCost + $shipping; $results['productcost'] = number_format($productCost, 2); $results['freightcost'] = number_format($shipping, 2); return $results; } function calculate_shipping(){ // Check for form submission: if (isset($_POST['submitted']) && isset($_POST['formKey']) && $_POST['formKey'] == 'shippingcost') { if(!empty($_POST['weight'])){ $shippingRate = $this->getWeightRate($_POST['weight']); } if(!empty($_POST['length']) && !empty($_POST['width']) && !empty($_POST['height'])) { $this->volume = $this->calculateVolume($_POST['length'], $_POST['width'], $_POST['height']); $shipping = $this->getVolumeRate($this->volume); $shippingRate = number_format($shipping, 2); } } // End of main isset() IF. return $shippingRate; } function calculate_ship_rate(){ // Check for form submission: if (isset($_POST['submitted']) && isset($_POST['formKey']) && $_POST['formKey'] == 'shipping') { // Minimal form validation: if ( is_numeric($_POST['price']) ) { if(!empty($_POST['weight'])){ $shippingRate = $this->getWeightRate($_POST['weight']); } else { $volume = $this->totalVolume($_POST['length'], $_POST['width'], $_POST['height']); //$volume = $_POST['volume']; $shippingRate = $this->getVolumeRate($volume); } $result = $this->totalProductCost($_POST['price'], $shippingRate, $_POST['quantity']); } else { } } // End of main isset() IF. return $result; } function shipping_calculator_form(){ ?> <div id="shipping-calculator"> <div id="lb-title-header">Shipping Calculator</div> <form action="<?php echo $this->postUrl; ?>" method="post" id="calculate"> <div class="fieldset"> <table cellspacing="3" cellpadding="3"> <tr valign="top"> <td class="label"><label>Product Cost:</label></td><td><input id="price" type="text" name="price" size="5" maxlength="10" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>" /></td><td></td> </tr> <tr valign="top"> <td class="label"><lable>Qty:</lable></td><td><input id="quantity" type="text" name="quantity" size="5" maxlength="6" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></td><td></td> </tr> <tr valign="top"> <td class="label"><label>Weight:</label></td><td><input id="weight" type="text" name="weight" size="5" maxlength="5" value="<?php if (isset($_POST['weight'])) echo $_POST['weight']; ?>" /></td><td><i>lbs</i></td> </tr> <tr valign="top"> <td class="label"><lable>Length:</lable></td><td><input id="length" type="text" name="length" size="5" maxlength="8" value="<?php if (isset($_POST['length'])) echo $_POST['length']; ?>" /></td><td><i>inches</i></td> </tr> <tr valign="top"> <td class="label"><lable>Width:</lable></td><td><input id="width" type="text" name="width" size="5" maxlength="8" value="<?php if (isset($_POST['width'])) echo $_POST['width']; ?>" /></td><td><i>inches</i></td> </tr> <tr valign="top"> <td class="label"><lable>Height:</lable></td><td><input id="height" type="text" name="height" size="5" maxlength="8" value="<?php if (isset($_POST['height'])) echo $_POST['height']; ?>" /></td><td><i>inches</i></td> </tr> <tr valign="top"> <td class="label"><label>Add Insurance?:</label></td><td><input type="checkbox" name="insurance" id="insurance" value="true" /></td><td></td> </tr> <tr valign="top"> <td><input id="submit" type="submit" name="submit" value="Calculate!" /></td><td></td><td></td> </tr> </table> </div> <input type="hidden" name="formKey" value="shipping" /> <input type="hidden" name="submitted" value="TRUE" /> </form> <div id="responce"></div> </div> <?php } } ?> The Result script <div id="shipcal"> <?php if(!class_exists('ShippingCalculator')){ include('class.shippingCalc.php'); $calculate = new ShippingCalculator(); //instantiate the shipping calculator class } if(isset($_POST['submit'])){ $calculate = new ShippingCalculator(); //instantiate the shipping calculator class // Set the shipping tax $calculate->tax = 17.5; // tax rate $calculate->minInsurance = 15.00; // Minimum Insurance Fee $calculate->brokerageFee = 10.00; // Brokerage Fee // Calculate shipping charges $results = $calculate->calculate_ship_rate(); echo '<div class="results-heading">Your Total Shipment Cost</div><table>'; echo '<tr><td class="label productcost">Product Cost:</td> <td class="result productcost">$'.$results['productcost'].'</td></tr>'; echo '<tr><td class="label freightcost">Freight Cost:</td> <td class="result freightcost">$'.$results['freightcost'].'</td></tr>'; echo '<tr><td class="label insurance">Insurance:</td> <td class="result insurance">$'.$results['insurance'].'</td></tr>'; echo '<tr><td class="label brokagefee">Brokage Fee:</td> <td class="result brokagefee">$'.$results['brokeragefee'].'</td></tr>'; echo '<tr><td class="label grandtotal">Grand Total:</td> <td class="result grandtotal">$'.$results['grandtotal'].'</td></tr>'; echo '</table>'; echo '<div class="calbutton"><a href="shipcal.php">« Back</a></div>'; } else { $calculate->postUrl = 'shipcal.php'; $calculate->shipping_calculator_form(); } ?> </div> I need to be able to calculate the shipping rates (freight cost) from the weight or volume (length, width, height) entries and without out the need to enter the product cost or quantity. Please?? I need this ASAP.. Any help, advise or instructions on how to do this will be greatly appreciated. Thanks in advanced, Winchester
  5. Hi, I need some help with my coding. Mate (MySQL Ajax Table Editor) is a grid system. There are 4 files that the grid needs to work: - Index.php: the page to display the grid (the grid configurations) - AjaxTableEditor.php: the PHP classes for the grid - ajax_table_editor.js: the javascript to handle the Ajax functions - Common.php: not sure what to call this file, but it hold the header of the grid pages. I've managed to load my tables but having problems with the follow areas: 1) Master/Detail (pop up): The developer provided the codes to make this happen, but he never seems to be able to tell where to put the codes and how to configure it. Anyway, after working on it, I figured out where the most of the codes should go and now it pops up. Only, it pops up in a new window instead of a lightbox. My tables/grids: - TableA: holds the Customers details. - TableB: holds the Jobs that the customers posted by the customers to be done. A Job could have multiple tasks - TableC: holds the Workers detials. - TableD: holds the Tasks for the Jobs. My Grid for TableB. When I click on a row, I what the Tasks for that job to show up in the popup. Right now, ALL the jobs shows up. Master Gird: sns-prm.php (the index.php): <?php /* * Mysql Ajax Table Editor * * Copyright (c) 2008 Chris Kitchen <info@mysqlajaxtableeditor.com> * All rights reserved. * * See COPYING file for license information. * * Download the latest version from * http://www.mysqlajaxtableeditor.com */ require_once('sns-common.php'); require_once('php/lang/LangVars-en.php'); require_once('php/AjaxTableEditor.php'); class Example1 extends Common { var $Editor; function displayHtml() { ?> <br /> <div align="left" style="position: relative;"><div id="ajaxLoader1"><img src="images/ajax_loader.gif" alt="Loading..." /></div></div> <br /> <div id="historyButtonsLayer" align="left"> </div> <div id="cm-header"><h1>Shop n Ship Jamaica</h1><h3>Purchase Request Manager</h3></div> <div id="historyContainer"> <div id="information"> </div> <div id="titleLayer" style="padding: 2px; font-weight: bold; font-size: 18px; text-align: center;"> </div> <div id="searchButtonsLayer" align="center"> </div> <div id="tableLayer" align="center"> </div> <div id="recordLayer" align="center"> </div> </div> <script type="text/javascript"> trackHistory = true; var ajaxUrl = '<?php echo $_SERVER['PHP_SELF']; ?>'; toAjaxTableEditor('update_html',''); </script> <?php } function initiateEditor() { $tableColumns['PRID'] = array('display_text' => 'PR ID', 'perms' => 'TVQSXO'); $tableColumns['SNSID'] = array('display_text' => 'SNS ID', 'perms' => 'EVTAXQSHO'); $tableColumns['RequestDate'] = array('display_text' => 'Request Date', 'perms' => 'VTXQSHO', 'display_mask' => 'date_format(RequestDate,"%d %M %Y")', 'calendar' => '%d %B %Y'); $tableColumns['PaymentCodes'] = array('display_text' => 'Transaction #', 'perms' => 'EVTAXQSHO'); $tableColumns['StatusID'] = array('display_text' => 'Status', 'perms' => 'VTEAXQSHO', 'join' => array('table' => 'cm_status', 'column' => 'StatusID', 'display_mask' => "Status", 'type' => 'left')); $tableColumns['UJID'] = array('display_text' => 'Agent', 'perms' => 'EVAXQSHO', 'join' => array('table' => 'cm_users', 'column' => 'user_id', 'display_mask' => "concat(cm_users.first_name,' ',cm_users.last_name)", 'type' => 'left')); $tableColumns['ProcessDate'] = array('display_text' => 'Process Date', 'perms' => 'EVTAXQSHO', 'display_mask' => 'date_format(ProcessDate,"%d %M %Y")', 'calendar' => '%d %B %Y'); $tableName = 'cm_requests'; $primaryCol = 'PRID'; $errorFun = array(&$this,'logError'); $permissions = 'EAVIDQSXHO'; $this->Editor = new AjaxTableEditor($tableName,$primaryCol,$errorFun,$permissions,$tableColumns); $this->Editor->setConfig('tableInfo','cellpadding="1" width="98%" class="mateTable"'); $this->Editor->setConfig('orderByColumn','PRID'); $this->Editor->setConfig('ascOrDesc','desc'); $this->Editor->setConfig('addRowTitle','Add Log Entry'); $this->Editor->setConfig('editRowTitle','Edit Log Entry'); //$this->Editor->setConfig('iconTitle','Edit Employee'); // This goes in the initiate editor function $userActions = array('show_row_details' => array(&$this,'showRowDetails')); $this->Editor->setConfig('userActions',$userActions); $this->Editor->setConfig('extraRowInfo','onclick="showRowDetails(\'#primaryColValue#\',\'#rowNum#\');" style="cursor: pointer;"'); } function Example1() { if(isset($_POST['json'])) { session_start(); // Initiating lang vars here is only necessary for the logError, and mysqlConnect functions in Common.php. // If you are not using Common.php or you are using your own functions you can remove the following line of code. $this->langVars = new LangVars(); $this->mysqlConnect(); if(ini_get('magic_quotes_gpc')) { $_POST['json'] = stripslashes($_POST['json']); } if(function_exists('json_decode')) { $data = json_decode($_POST['json']); } else { require_once('php/JSON.php'); $js = new Services_JSON(); $data = $js->decode($_POST['json']); } if(empty($data->info) && strlen(trim($data->info)) == 0) { $data->info = ''; } $this->initiateEditor(); $this->Editor->main($data->action,$data->info); if(function_exists('json_encode')) { echo json_encode($this->Editor->retArr); } else { echo $js->encode($this->Editor->retArr); } } else if(isset($_GET['export'])) { session_start(); ob_start(); $this->mysqlConnect(); $this->initiateEditor(); echo $this->Editor->exportInfo(); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-type: application/x-msexcel"); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$this->Editor->tableName.'.csv"'); exit(); } else { $this->displayHeaderHtml(); $this->displayHtml(); $this->displayFooterHtml(); } } } $lte = new Example1(); ?> Detail Grid: sns-prim.php (the index.php): <?php /* * Mysql Ajax Table Editor * * Copyright (c) 2008 Chris Kitchen <info@mysqlajaxtableeditor.com> * All rights reserved. * * See COPYING file for license information. * * Download the latest version from * http://www.mysqlajaxtableeditor.com */ require_once('sns-common.php'); require_once('php/lang/LangVars-en.php'); require_once('php/AjaxTableEditor.php'); class Example1 extends Common { var $Editor; function displayHtml() { ?> <br /> <div align="left" style="position: relative;"><div id="ajaxLoader1"><img src="images/ajax_loader.gif" alt="Loading..." /></div></div> <br /> <div id="historyButtonsLayer" align="left"> </div> <div id="historyContainer"> <div id="information"> </div> <div id="titleLayer" style="padding: 2px; font-weight: bold; font-size: 18px; text-align: center;"> </div> <div id="searchButtonsLayer" align="center"> </div> <div id="tableLayer" align="center"> </div> <div id="recordLayer" align="center"> </div> </div> <script type="text/javascript"> trackHistory = false; var ajaxUrl = '<?php echo $_SERVER['PHP_SELF']; ?>'; toAjaxTableEditor('update_html',''); </script> <?php } function initiateEditor() { $tableColumns['PRIID'] = array('display_text' => 'PRI ID', 'perms' => 'TVQSXO'); $tableColumns['SNSID'] = array('display_text' => 'SNS ID', 'perms' => 'VTXQSHO'); $tableColumns['PRID'] = array('display_text' => 'PR ID', 'perms' => 'TVQSXO'); $tableColumns['ItemURL'] = array('display_text' => 'Item URL', 'perms' => 'VTXQSHO'); $tableColumns['ItemDesc'] = array('display_text' => 'Description', 'perms' => 'VTXQSHO'); $tableColumns['ItemQty'] = array('display_text' => 'Qty', 'perms' => 'VTXQSHO'); $tableColumns['ItemCost'] = array('display_text' => 'Unit Cost', 'perms' => 'VTXQSHO'); $tableColumns['ItemTax'] = array('display_text' => 'Sale Tax', 'perms' => 'VXQSHO'); $tableColumns['ItemShipCost'] = array('display_text' => 'Shipping Cost', 'perms' => 'VXQSHO'); $tableColumns['ItemTotalCost'] = array('display_text' => 'Total Cost', 'perms' => 'VXQSHO'); $tableColumns['ItemWeight'] = array('display_text' => 'Weight', 'perms' => 'VXQSHO'); $tableColumns['ItemLength'] = array('display_text' => 'Length', 'perms' => 'VXQSHO'); $tableColumns['ItemWidth'] = array('display_text' => 'Width', 'perms' => 'VXQSHO'); $tableColumns['ItemHeight'] = array('display_text' => 'Height', 'perms' => 'VXQSHO'); $tableColumns['Instructions'] = array('display_text' => 'Instructions', 'perms' => 'VXQSHO'); $tableColumns['StatusID'] = array('display_text' => 'Status', 'perms' => 'VTEAXQSHO', 'join' => array('table' => 'cm_status', 'column' => 'StatusID', 'display_mask' => "Status", 'type' => 'left')); $tableName = 'cm_request_items'; $primaryCol = 'PRIID'; $errorFun = array(&$this,'logError'); $permissions = 'VIQSXHO'; $this->Editor = new AjaxTableEditor($tableName,$primaryCol,$errorFun,$permissions,$tableColumns); $this->Editor->setConfig('tableInfo','cellpadding="1" width="98%" class="mateTable"'); $this->Editor->setConfig('orderByColumn','PRIID'); $this->Editor->setConfig('ascOrDesc','asc'); //$this->Editor->setConfig('addRowTitle','Add Log Entry'); //$this->Editor->setConfig('editRowTitle','Edit Log Entry'); //$this->Editor->setConfig('iconTitle','Edit Employee'); if(isset($_GET['client_id'])) { $this->Editor->setConfig('sqlFilters',"cm_request_items.PRID = '".$_GET['client_id']."'"); } } function Example1() { if(isset($_POST['json'])) { session_start(); // Initiating lang vars here is only necessary for the logError, and mysqlConnect functions in Common.php. // If you are not using Common.php or you are using your own functions you can remove the following line of code. $this->langVars = new LangVars(); $this->mysqlConnect(); if(ini_get('magic_quotes_gpc')) { $_POST['json'] = stripslashes($_POST['json']); } if(function_exists('json_decode')) { $data = json_decode($_POST['json']); } else { require_once('php/JSON.php'); $js = new Services_JSON(); $data = $js->decode($_POST['json']); } if(empty($data->info) && strlen(trim($data->info)) == 0) { $data->info = ''; } $this->initiateEditor(); $this->Editor->main($data->action,$data->info); if(function_exists('json_encode')) { echo json_encode($this->Editor->retArr); } else { echo $js->encode($this->Editor->retArr); } } else if(isset($_GET['export'])) { session_start(); ob_start(); $this->mysqlConnect(); $this->initiateEditor(); echo $this->Editor->exportInfo(); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-type: application/x-msexcel"); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$this->Editor->tableName.'.csv"'); exit(); } else { $this->displayHeaderHtml(); $this->displayHtml(); //$this->displayFooterHtml(); } } } $lte = new Example1(); ?> These are the codes that the developer gave: To be added to the master grid page: // This goes in the initiate editor function $userActions = array('show_row_details' => array(&$this,'showRowDetails')); $this->Editor->setConfig('userActions',$userActions); $this->Editor->setConfig('extraRowInfo','onclick="showRowDetails(\'#primaryColValue#\',\'#rowNum#\');" style="cursor: pointer;"'); To be added to AjaxTableEditor.php: // php function function showRowDetails($info) { // Select and format row details here $html = '<tr id="'.$info->rowNum.'_row_details" style="display: table-row;"><td colspan="99">Row details for id '.$info->id.' go here</td></tr>'; $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$(\'row_'.$info->rowNum.'\').insert({after: \''.$html.'\'});'); } To be added to ajax_table_editor.js: // javascript function function showRowDetails(id,rowNum) { var info = {id: id, rowNum: rowNum}; if($(rowNum+'_row_details') != null) { $(rowNum+'_row_details').remove(); } else { toAjaxTableEditor('show_row_details',info); } } Alternative code for the ajax_table_editor.js file to be used instead of the one above: /// javascript function function showRowDetails(id,rowNum) { window.open('RowDetails.php?id='+id,'detail_popup','toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=600,left=100,top=100'); } I sent him a private message about this problem and he sent me this piece of code but with no instructions as to what to do with it: if(isset($_GET['client_id'])) { $this->Editor->setConfig('sqlFilters',"client_id = '".$_GET['client_id']."'"); } 2) There are some tables that I need to join to the main tables to get certain information. For instance (from my Tables examples above), I want to add the customer and the worker's name to the Detail grid view. TableA doesn't have a column for the TableC ID, but TableC has the TableA ID. With this grid system I can join TableA and TableC to TableB easily, but I need to join TableD to TableA to get the name of the Customer. Please help!! I'm almost out of time on this part of the project and the developer of Mate seems to be very busy. - Mate download page (free version): http://www.mysqlajaxtableeditor.com/GetMateNow.php - Mate forum page: http://www.mysqlajaxtableeditor.com/discussmate/index.php Best Regards, ___________ Winchester
  6. If this is not the right way to go about this or it just simply cannot be done, will some body tell me this please? If it can be done or there is a better/easier way to do this, can someone please point me to where I can find the information (if it is available. Will someone just say something please!!!
  7. Hi Again, Any help will be appreciated. Thanks Best Regards, _________ Winchester
  8. Oppps.. that was the wrong version of the caching.php script. Here's the right one <?php /* * Caching A small PHP class to */ class Caching { var $filePath = ""; var $apiURI = ""; function __construct($filePath, $apiURI) { //check if the file path and api URI are specified, if not: break out of construct. if (strlen($filePath) > 0 && strlen($apiURI) > 0) { //set the local file path and api path $this->filePath = $filePath; $this->apiURI = $apiURI; //does the file need to be updated? if ($this->checkForRenewal()) { //get the data you need $xml = $this->getExternalInfo(); //save the data to your file $this->stripAndSaveFile($xml); } else { //no need to update the file return true; } } else { echo "No file path and / or api URI specified."; return false; } } function checkForRenewal() { //set the caching time (in seconds) $cachetime = (60 * 60 * 24 * 1); //one day worth of seconds //get the file time $filetimemod = filemtime($this->filePath) + $cachetime; //if the renewal date is smaller than now, return true; else false (no need for update) if ($filetimemod < time()) { return true; } else { return false; } } function getExternalInfo() { if ($xml = @simplexml_load_file($this->apiURI)) { return $xml; } else { return false; } } function stripAndSaveFile($xml) { //put the artists in an array $tbill = $xml->TBILLS->ANNOUNCE; //building the xml object for SimpleXML $output = new SimpleXMLElement("<announce></announce>"); //get only the top 10 for ($i = 0; $i < 10; $i++) { //create a new artist $insert = $output->addChild("announce"); //insert name and playcount childs to the artist $insert->addChild("link", $tbill[$i]->LINK); $insert->addChild("date", $tbill[$i]->DATE); } //save the xml in the cache file_put_contents($this->filePath, $output->asXML()); } } ?>
  9. I can trying to create a script for caching an XML files. The problem is that this XML file was poorly constructed and I can't do anything about it. XML file: http://www.boj.org.jm/uploads/tbills.xml I would like to have the cached xml file to be restructured like this: <tbills> <tbill> <title>Announcement</title> <doc>www.boj.org.jm/pdf/tbill_press_release_2010-07-13.doc</doc> <date>Jul 14 2010 12:00am</date> </tbill> <tbill> <title>Results</title> <doc>www.boj.org.jm/pdf/tbill_results_2010-june-23.doc</doc> <date>Jun 23 2010 12:00am</date> </tbill> </tbill> I can find tutorials that works if the source XML data is properly structured, but I can never seem to find one that addresses situations like this. I found this code in a tutorial and tried to edit it to what I would need, but I'm stuck with 2 things. [*]How do I get this to change the structure of the XML when caching How do I use the call script and where do I put it? [*] Caching script (caching.php) <?php /* * Caching A small PHP class to */ class Caching { var $filePath = ""; var $apiURI = ""; function __construct($filePath, $apiURI) { //check if the file path and api URI are specified, if not: break out of construct. if (strlen($filePath) > 0 && strlen($apiURI) > 0) { //set the local file path and api path $this->filePath = $filePath; $this->apiURI = $apiURI; //does the file need to be updated? if ($this->checkForRenewal()) { //get the data you need $xml = $this->getExternalInfo(); //save the data to your file $this->stripAndSaveFile($xml); } else { //no need to update the file return true; } } else { echo "No file path and / or api URI specified."; return false; } } function checkForRenewal() { //set the caching time (in seconds) $cachetime = (60 * 60 * 24); //one day worth of seconds //get the file time $filetimemod = filemtime($this->filePath) + $cachetime; //if the renewal date is smaller than now, return true; else false (no need for update) if ($filetimemod < time()) { return true; } else { return false; } } function getExternalInfo() { if ($xml = @simplexml_load_file($this->apiURI)) { return $xml; } else { return false; } } function stripAndSaveFile($xml) { //put the artists in an array $tbill = $xml->TBILLS->ANNOUCE; //building the xml object for SimpleXML $output = new SimpleXMLElement("<tbill><title></title></tbill>"); //get only the top 10 for ($i = 0; $i < 10; $i++) { //create a new artist $insert = $output->addChild("artist"); //insert name and playcount childs to the artist $insert->addChild("name", $artists[$i]->name); $insert->addChild("playcount", $artists[$i]->playcount); } //save the xml in the cache file_put_contents($this->filePath, $output->asXML()); } } ?> Calling script (calling.php) <?php ini_set('display_errors', 1); error_reporting(E_ALL); include('caching.php'); $caching = new Caching($_SERVER['DOCUMENT_ROOT']."/tbills.xml", "http://www.boj.org.jm/uploads/tbills.xml"); ?> Thanks in advance. Best Regards, _________ Winchester
  10. Thank you very much Ken.. the script worked great and by far much faster than what I did before.
  11. Hello Ken.. Thank you very much for helping. I will give your codes a try right away Hello MadTechie.. Thanks for your suggestion.. Someone made this suggestion before and I've been searching for pages that will explain how to do this. How would I go about caching the file?
  12. Hello Ram4nd.. Thank you very much for responding. I'm very new to php. In fact I'm more of a designer and not so much a developer. Could you explain a little about how I should go about this? Could you point me to some scripts that I could learn from? I was thinking, I could find a way to copy the xml data to another xml file on my server and have the script take the info from there. I'm thinking I will need a cron job to have the local xml file update daily. Does this sound like a practical and do-able solution?
  13. Is there someone that can help me with? Pretty please?
  14. I read the tutorial, "Handling XML Data" and created this script from it. Excellent tutorial by the way Here is my script: <?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)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.