Jump to content

Mal1

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by Mal1

  1. As I said, there's a whole lot of code which all seems interlinked, it checks to see if items are on sale, or specific sizes within an ID are on sale, it checks for site-wide promotions etc etc. I'll get someone to have a look at it later and see if I can get it posted up but I don't want to and it wouldn't be fair to post up a thousand lines of code.
  2. I think something like this is happening. It retrieves the results but I think it does a lot of checks (to see if a promotion or discount is active and if it is a valid result etc.) maybe it's checking this each time rather than just once. I'm not 100% sure if this is the code, there's pages of code that it could be so I've posted what I think to be the most likely segment and there's code within other files as well. Will maybe have a better idea when the boss comes in, he's from a software design background so might be able to read the code better (although not php/sql). If it's not someone please let me know so I can get it removed, it's not something I want up online: <?php //echo "rug_count: ".count($rugs_all)."<br />"; //echo "<br />---FULL---".$sql; $page_count = $this->query($count_sql); $pages = ceil(array_shift(array_shift($page_count)) / $search_results_per_page); $search_results_per_page = 10; if(isset($_GET['page'])) { $cur_page = intval($_GET['page'])-1; if($cur_page==0) { $sql .= " LIMIT 0, $search_results_per_page"; } else { $sql .= " LIMIT ".($search_results_per_page * $cur_page).", $search_results_per_page"; } } else { $sql .= " LIMIT 0, $search_results_per_page"; } //echo $sql; // page the result set $rugs_search = $this->query($sql); $rugs = array(); foreach ( $rugs_search as $rug ) { $tmp = new Rug($rug['id']); // apply promotions $tmp->applyPromotion(); if(!isset($_GET['admin-search']) OR (isset($_GET['admin-search']) && $_GET['admin-search'] == 0)){ // eliminate rugs without any stock if ( $tmp->useQuantity() ) { $stock = 0; // look for active stock foreach ( $tmp->data['stock']->data as $stock => $values ) { if ( $values['active'] == '1' && $values['stock'] > 0 ){ $stock += $values['stock']; } } if ( $stock > 0 ){ $rugs[] = $tmp->data; } }else{ $rugs[] = $tmp->data; } }else{ $rugs[] = $tmp->data; } } return array( 'this' => $rugs, 'all' => $rugs_all, 'sql' => $sql_all) ; }
  3. Will try to post tomorrow... will need to find the actual pages that are sending the queries - there are probably several interlinked. Thanks.
  4. Complete beginner here so just really looking for pointers on where to start. Been doing a bit of bug fixing on one of our sites because the past 3 programmers we've hired have disappeared on us. The big issue I'm looking to solve is the load time of a search. Our website (Love-Rugs) is taking about 6 or 7 seconds to perform a blank search (basically a quick browse) whereas out other site (Little-Persia) takes about a second. It wouldn't be so bad if it was just the initial search but going from one page (only 10 products listed per page) to the next takes the same amount of time. There seems to be an awful lot of queries (around 130-150) on the searches - however - when using some of the search options e.g. type and fabric to refine the search the queries actually stay high but the time to process the results is reduced significantly. I don't really understand why if the queries are still high the search time is much lower unless it's to do with the number of results returned. However this does not explain why Little-Persia (which has far more products on it) takes less time as there would obviously be more results. I realize that without code this isn't easy to answer so I'm just looking to see if someone can point me in the right direction to look at just now.
  5. Ok I get that and was expecting it, but is there any way around it (bar "don't use Dreamweaver"). It's the -> that's causing the colour rendering to break. It's not effecting the code but it would make it a lot more readable if fixed.
  6. Newbie at this. In Dreamweaver I've got a bit of code (below) and under it the colour coding stops working, I know it's to do with the line: $rug_obj->applyPromotion(); but I don't know if there's a way to fix this - the line of code is vital to the page so I can't just remove it. <?php // check for promos $rug_obj = new Rug($rug['id']); $rug_obj->applyPromotion();
  7. By that I mean I've tried adding a field: "manual_del" to the database but not sure how to link up the checkbox being checked or not to the database.
  8. This is the code from this page. I'm more concerned with how it passes it on to other pages. I have view order and view invoices sections where delivery is being displayed - when that checkbox is not ticked the delivery should be 0 on these but right now it always shows the calculated delivery. This is a manual order - there's another section elsewhere where a customer can select 'collect from store' I've been able to use code to say if collect_from_store == '1' then delivery = 0. I'm looking to do the same thing if this checkbox is not checked... <?php $action = 'manual_order'; $_SESSION['action'] = $action; //echo "<pre>"; //print_r($_SESSION); //echo "</pre>"; //echo "<pre>"; //print_r($_POST); //echo "</pre>"; ?> <script type="text/javascript" src="js/jquery/orders.js"></script> <div id="menuopt"> <a href="admin.php">Back to admin</a> </div> <div id="list"> <div id="inside2"> <form action='admin.php' method="post"> <input type="hidden" name="action" value="<?php echo $action;?>" /> <?php if(isset($_GET['remove_manual_rug_id'])) { unset($_SESSION['manual_order_rugs'][$_GET['remove_manual_rug_id']]); } if(is_array($_POST['add_rug_to_manual_order'])) { $index = 0; foreach($_POST['add_rug_to_manual_order'] as $key => $val ) $index = $key; //echo "SDA$key"; $_SESSION['manual_order_rugs'][$_POST['manual_stock_id'][$index]]['rug_id'] = $_POST['manual_rug_id'][$index]; $_SESSION['manual_order_rugs'][$_POST['manual_stock_id'][$index]]['delivery_cost'] = $_POST['delivery_cost'][$index]; $_SESSION['manual_order_rugs'][$_POST['manual_stock_id'][$index]]['price'] = $_POST['rug_price'][$index]; $_SESSION['manual_order_rugs'][$_POST['manual_stock_id'][$index]]['qty'] = $_POST['rug_qty'][$index]; $_SESSION['manual_order_rugs'][$_POST['manual_stock_id'][$index]]['desc'] = $_POST['manual_rug_desc'][$index]; } if(sizeof($_SESSION['manual_order_rugs'])>0) { echo "<table cellspacing='5'><tr><th>Reference</th><th>Description</th><th>Qty</th><th>Price</th><th>Delivery</th><th>Action</th></tr>"; $total = 0; $total_del = 0; foreach($_SESSION['manual_order_rugs'] as $key=>$value) { echo "<tr><td><strong>#".$value['rug_id']."</strong></td>"; echo "<td>".$value['desc']."</td>"; echo "<td>".$value['qty']."</td>"; echo "<td align='right'>£".$value['price']."</td>"; echo "<td align='right'>£".$value['delivery_cost']."</td>"; echo "<td><a href='admin.php?action=$action&id=".$_GET['id']."&remove_manual_rug_id=".$key."' style='text-decoration:underline'>delete from order</a></td></tr>"; $total = $total + (floatval($value['price']) * floatval($value['qty'])); $total_del = $total_del + (floatval($value['delivery_cost']) * floatval($value['qty'])); } echo "<tr><td colspan='2' align='right'><strong>Totals: </strong></td><td> </td>"; echo "<td align='right'><strong>£".number_format($total, 2)."</strong></td>"; echo "<td align='right'><strong>£".number_format($total_del, 2)."</strong></td>"; echo "</tr>"; echo "</table><br />"; } if($_POST['do_add_rug'] != 'Enter order') { ?> Lookup rug by reference: <input type='text' size='5' name='lookup_id'> <input type='submit' name='perform_lookup' value='Lookup' /> <?php if($_POST['perform_lookup'] == 'Lookup' and $_POST['lookup_id'] != "" and !isset($_POST['add_rug_to_manual_order'])) { $rug = new Rug($_POST['lookup_id']); if ( $rug->error ) echo "<br /><p>No valid matches</p><br />"; else { echo "<br /><p>Found rug(s): <br />"; foreach ( $rug->data['stock']->data as $line ) { // calculate the delivery cost of this item $stock = new Stock($rug->data['id'], 0); $delivery_cost = $stock->calculateDelivery($line['id']); $desc = $line['width']."m x ".$line['length']."m, ".$rug->data['type_name']; if(strlen($rug->data['subtype_name'])>0) $desc .= ", ".$rug->data['subtype_name']; if(strlen($rug->data['designname'])>0) $desc .= ", ".$rug->data['designname']; if(strlen($rug->data['designer_name'])>0) $desc .= " (".$rug->data['designer_name'].")"; if(strlen($rug->data['pattern_name'])>0) $desc .= ", ".$rug->data['pattern_name']; if(strlen($rug->data['fabric_name'])>0) $desc .= ", ".$rug->data['fabric_name']; //if ( $line['stock'] > 0 && $line['stock_override'] == 0 ) if ( $line['stock_override'] == 0 ) $stock = " (".$line['stock']." in stock)"; elseif ( $rug->data['stock_override'] == 1 ) $stock = " (stock override)"; echo $desc; echo " <small>qty:</small><input type='text' name='rug_qty[".$line['id']."]' size='3' value='1' /> ".$stock; echo " <small>price:</small><input type='text' name='rug_price[".$line['id']."]' size='7' value=".$line['actual_price']." /> "; echo " <small>delivery:</small><input type='text' name='delivery_cost[".$line['id']."]' size='7' value=".$delivery_cost." /> "; echo "<input type='hidden' name='manual_rug_id[".$line['id']."]' value=".$rug->data['id']." />"; echo "<input type='hidden' name='manual_stock_id[".$line['id']."]' value=".$line['id']." />"; //echo "<input type='hidden' name='manual_delivery_cost[".$line['id']."]' value=".$delivery_cost." />"; echo "<input type='hidden' name='manual_rug_desc[".$line['id']."]' value=\"".$desc."\" />"; echo "<input type='submit' name='add_rug_to_manual_order[".$line['id']."]' value='Add to order' />"; echo "</p>"; } } } $fields = array("firstname"=>"Forename", "lastname"=>"Surname", "email"=>"Email", "street_adress"=>"Address Line 1", "suburb"=>"Address Line 2", "postcode"=>"Postcode", "city"=>"City", "country"=>"Country", "phone"=>"Phone"); $shipping_fields = array("shipping_street_adress"=>"Shipping Address 1", "shipping_suburb"=>"Shipping Address 2", "shipping_postcode"=>"Shipping Postcode", "shipping_city"=>"Shipping City", "shipping_country"=>"Shipping Country", "shipping_phone"=>"Shipping Phone"); echo "<br /><div class=\"left\">"; foreach($fields as $fieldname => $displayname) { echo "<span class='form'><label>".$displayname."</label><input type='text' name='".$fieldname."'"; echo " value=\"".$_POST[$fieldname]."\" /></span>"; } ?> <span class="form"><label>State:</label><select name="order_state"> <option value='5' <?php if ($_POST['order_state'] == '5' ) echo 'selected'; ?>>Completed</option> <option value='4' <?php if ($_POST['order_state'] == '4' ) echo 'selected'; ?>>Returned</option> <option value='3' <?php if ($_POST['order_state'] == '3' ) echo 'selected'; ?>>Handling</option> <option value='2' <?php if ($_POST['order_state'] == '2' ) echo 'selected'; ?>>Received</option> <option value='1' <?php if ($_POST['order_state'] == '1' ) echo 'selected'; ?>>Abandoned</option> </select></span> <span class="form"> </span> <span class="form"> </span> <span class="form"><h2>Totals</h2></span> <?php // add a checkbox for delivery charges echo '<span class="form"><label>Delivery Charges</label>'; echo '<input type="checkbox" name="del_charges" id="del_charges" value="1" class="boxes" '; if ( isset($_POST['del_charges']) && !empty($_POST['del_charges']) ) echo 'checked="checked"'; echo '/>'; ?> <span class='form'> <label>Delivery Total:</label> <input type='text' name='total_del' id='total_del' readonly="readonly" class="readonly off" value="<?php echo $total_del; ?>" /> </span> <span class='form'> <label>Sub Total:</label> <input type='text' name='total' id='total' readonly="readonly" class="readonly" value="<?php echo $total; ?>" /> </span> <span class="form"> </span> <span class='form'> <label>Total:</label> <input type='text' name='total_order' id="total_order" readonly="readonly" class="readonly" value="<?php echo $total; ?>" /> </span> <input type="submit" class="save" name="do_add_rug" value="Enter order" /> </div> <div class='right'> <span class='form'> <label>Payment Method</label> <input type='text' name='payment_method' value="<?php echo $_POST['payment_method']; ?>" /> </span> <span class='form'> <label>Customer Source</label> <input type='text' name='customer_source' value="<?php echo $_POST['customer_source']; ?>" /> </span> <span class="form"> </span> <?php foreach($shipping_fields as $fieldname => $displayname) { echo "<span class='form'><label>".$displayname."</label><input type='text' name='".$fieldname."'"; echo " value=\"".$_POST[$fieldname]."\" /></span>"; } // add a textarea for notes echo '<span class="form"><label>Notes</label><textarea name="notes" rows="8" cols="32" >'.$_POST['notes'].'</textarea>'; ?> </div> </form> <?php } else { echo "COMPLETED ORDER:".$completed_order_id."<br />"; print_r($_POST); print_r($_SESSION); } /* <!-- <h3>Order: <?php echo $order['id']; ?></h3> <div id="products"> <div class="headers"> <p class="products">Product(s)</p> <p class="price">Price</p> </div> <!-- //product --> <?php $total = 0; ?> <?php foreach ($rugs as $rug): ?> <div class="product"> <div class="product_photo"> <img src="img/<?php if ($rug['main_photo_id']) echo $rug['id']."_".$rug['main_photo_id']; else echo "nophoto"; ?>_small.jpg" width="120" height="160" alt="" /> <span> <p class="txt">Reference: R<?php echo $rug['id']; ?></p> <p class="txt">Length: <?php echo round($rug['length']/0.3, 2); ?> ft (<?php echo $rug['length'];?> m)</p> <p class="txt">Width: <?php echo round($rug['width']/0.3, 2); ?> ft (<?php echo $rug['width'];?> m)</p> </span> <a href="?action=view_rug&id=<?php echo $rug['id']; ?>"><?php echo $rug['short_description']; ?></a> </div> <div class="how_much"> <p class="pound">£<?php echo $rug['sold_price']; $total += $rug['sold_price']*$rug['order_qty']; ?></p> </div> </div> <?php endforeach; ?> <!-- // finish product --> </div> <p class="total">Total: £<?php echo $total; ?></p> <div id="contact_details"> <h5>Sold date: <?php echo $order['created']; ?></h5> <h5>Billing details</h5> <p>First Name: <?php echo $order['firstname']; ?></p> <p>Last Name: <?php echo $order['lastname']; ?></p> <p>Email: <?php echo $order['email']; ?></p> <p>Street Address: <?php echo $order['street_adress']; ?></p> <?php if ($order['suburb'] != ""): ?><p>Address line 2: <?php echo $order['suburb']; ?></p><?php endif; ?> <p>Post Code: <?php echo $order['postcode']; ?></p> <p>City: <?php echo $order['city']; ?></p> <p>County: <?php echo $order['county']; ?></p> <p>Country: <?php echo $order['country']; ?></p> <p>Telephone number: <?php echo $order['phone']; ?></p> <?php if (!isset($_POST['same_shipping_adress']) || !$_POST['same_shipping_adress']): ?> <h5>Shipping details</h5> <p>Street Address: <?php echo $order['shipping_street_adress']; ?></p> <?php if ($order['shipping_suburb'] != ""): ?><p>Address line 2: <?php echo $order['shipping_suburb']; ?></p><?php endif; ?> <p>Post Code: <?php echo $order['shipping_postcode']; ?></p> <p>City: <?php echo $order['shipping_city']; ?></p> <p>County: <?php echo $order['shipping_county']; ?></p> <p>Country: <?php echo $order['shipping_country']; ?></p> <p>Telephone number: <?php echo $order['shipping_phone']; ?></p> <?php endif; ?> </div> --> */ ?> </div> </div>
  9. Thanks, so it's probably a case of fixing what calculates $del_charges earlier on in the code? Or can I do something like: $_POST['del_charges' = 0.00];?
  10. Trying to fix existing some code (complete beginner here) on the company I work for website. There's a check-box which when ticked should apply delivery charges and if not it shouldn't - currently it's working in that on the same page it calculates the total cost correctly when checked or not checked but when passing on information it always passes on the delivery charge even if un-ticked... The simplest thing I can see would be to put an if statement in to say if (not ticked) then del_charges = 0.00. Any idea how I can do this in this instance? <?php // add a checkbox for delivery charges echo '<span class="form"><label>Delivery Charges</label>'; echo '<input type="checkbox" name="del_charges" id="del_charges" value="1" class="boxes" '; if ( isset($_POST['del_charges']) && !empty($_POST['del_charges']) ) echo 'checked="checked"'; echo '/>'; ?> Thanks.
  11. Ok, worked out that if I take the <head> tags and <title> <meta> tags etc. out of layout.tpl and put it in to the template pages I can name my titles individually on the page... although doing that means that there is no title for dynamic pages as the: <?php require_once("aper_consts.php"); if ( $_SERVER['HTTP_HOST'] != 'testing.local' ) echo ($title);?> Code is no longer used. I guess I could write some code to say if no title is found then use the code above? But then I'd still need to have: case "conditions"; $content_for_layout = $_GET['action']; break; For each new page I create
  12. I don't know why the title is determined in the index.php... there's a config.php page (which is 'required' by index.php) which has a title variable this seems to control generic titles across all dynamic pages/pages without titles. If I remove the $title = "Terms & Conditions"; from the code then the title reverts back to this generic title. The layout page has the head tags so the content pages wouldn't want to repeat these I'd imagine, even if I try to add a head and title tag to the content pages it doesn't show... the code used for the title in the layout is: <?php require_once("aper_consts.php"); if ( $_SERVER['HTTP_HOST'] != 'testing.local' ) echo ($title);?> The layout is a .tpl file as is the content that go in the middle of the layout. But if I don't put in the "case "conditions";..." into the index.php then it shows the homepage rather than the page it should display, which I think is related to this line at the end of index.php: default: // homepage $content_for_layout = "homepage"; break; The way the pages are loading I think it loads the layout.tpl with it's associated title and meta tags then within that php includes pretty much a page of html with linked css for styles. So the page source would show the title tags etc. for the layout and then later down the source it would show title tags that had been input at the content page (which obviously wouldn't work or overwrite those at the top of the page)... I don't really know or understand why it's built like that but are you saying having cases for each individual page on the index.php is normal for this method? Currently it is ok, there's only maybe 50-100 static content pages. I just don't get what happens if I end up with 1000s of pages - well I do know, I'll end up with a massive index.php!
  13. I've inherited a website and I'm no PHP expert. The way pages work is the urls are displayed as follows http://www.website.com/?action=<page_name> The pages are stored in a folder called templates as .tpl files. Amongst these is a file called layouts.tpl which is the website layout and menus, inside this there's a php include <?php include("template/$content_for_layout.tpl"); ?> which basically draws the content for the page from each static file when requested. In the index.php each static file has to be included as in the following example: case "conditions"; $title = "Terms & Conditions"; $content_for_layout = $_GET['action']; break; Without this in the index.php the page just reverts back to the homepage when you enter the url. I personally don't think this is right? It is handy to be able to manage all the page titles from a central location (index.php) but seems quite messy and cumbersome. I plan on making an articles or news folder and regularly creating pages and if each one has to be relayed this way in the index it is going to get big and cause headaches. Is there any way around this that anyone can see? ... On another note. If you type in the actual physical url of the file location it shows the html of the page without the layout i.e. http://www.website.com/template/conditions.tpl I don't know how common it is for websites to display "../?action=pagename" or similar but I wouldn't have thought it would be ideal for SEO purposes?
×
×
  • 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.