Jump to content

petenaylor

Members
  • Posts

    165
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

petenaylor's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Sorted! Thanks for your help folks!
  2. Thanks, can you help with the function I posted? I need it to output the array key as well as the value. for instance, if it chose $m18 then I want to to show $m18.
  3. Hi there Yes that's correct I just need to echo out the array key itself.
  4. Hi all I have a function below that searches an array and assigns it to $totalmonthlycost. I need to know how I get the array key of the chosen array value ($m12 - $m60) How do I return the array key in the below code? $monthvalues = array($m12,$m18,$m24,$m30,$m36,$m42,$m48,$m54,$m60); function closest($monthvalues, $number){ #does the array already contain the number? if($i = array_search( $number, $monthvalues)) return $i; #add the number to the array $monthvalues[] = $number; #sort and refind the number sort($monthvalues); $i = array_search($number, $monthvalues); #check if there is a number above it if($i && isset($monthvalues[$i-1])) return $monthvalues[$i-1]; //alternatively you could return the number itself here, or below it depending on your requirements } $totalmonthlycost = closest($monthvalues, $idealcostpermonth); Thanks for your help. Pete
  5. I think it is becuase the prices are stored as a varchar, do they need storing as decimal?
  6. Hi there That's great! I have an issue however, with the price. It seems to be ordering by price size and not price value. Here's the full query: " SELECT * FROM products LEFT JOIN product_options ON products.id = product_options.product_id WHERE products.category_id = '21' GROUP BY product_options.product_id ORDER BY product_options.price DESC " This does the following sort: 774: £2.99 1498: £2.75 1102: £14.99 1103: £11.99 1229: £13.19 8: £2.03 9: £1.75 As you can see it's sorting correctly to start with, and then does it by price size inbetween. Do I need to edit the price fetch in the query? Many thanks!
  7. Hi there, the database is taking care of the relationship.
  8. Hi all I have a question that relates to fetching records from a mySQL databse using php. Basically I have a table that stores product options and another table that stores the products themselves. There can be one or more product options for each product but there is always 1. The product options table has the product option ID, the product ID and the price. Thre product table has the product ID, category ID, name etc... The page has a $_GET on it with a category ID such as category.php?id=4&sortby=priceasc I need to firstly group all the product options by product ID and sort by the lowest price or highest price. Then I need to filter these by the category ID before outputting them to the browser. Hope someone can help me. Many thanks Pete
  9. Hi all I am trying to re-write the following URLs: The first I have managed OK: http://www.peten.co.uk/clientarea/ford/?page=new-car To: http://www.peten.co.uk/clientarea/ford/new-car By doing this: RewriteRule ^([A-Za-z\-]+)$ ?page=$1 [QSA] However, my next URL is: http://www.peten.co.uk/clientarea/ford/?page=new-car&vehicle=ford-ka I want this to become: http://www.peten.co.uk/clientarea/ford/new-car/vehicle/ford-ka I can't seem to get this to be re-written? I have tried: RewriteRule (.*)/(.*)/ index.php?page=$1&vehicle=$2 But his ruins all my images and some don't load? Can you help me re-write the URL? Many thanks Pete
  10. That's it! That's all I needed, thanks for your help!
  11. Hi there That's great, is there anyway of just pulling one instance of the product ID? So the result will be 6,3,4,5 ? I am trying to get just one instance of the product ID in a list. Thank you, I really appreciate your help. I'll close the other post too. Pete
  12. Hi there Thanks for your response, I have created a new table for the product options and attached it. What I need my script to do is order by the price column, smallest first and then bring back one instance of each of the product ids. Once I have the product ids in the correct order, I then need to pull info back from the database by the product id. Many thanks for your help.
  13. Hi all I am trying to write a piece of PHP code which will look through the attached database and fetch the product which has the cheapest price out of the 5 price columns. Sorry, I am not sure how to add in the mySQL into the text editor window, so I have attached a screenshot. Basically, I have a table for products and they will have up to 5 possible prices (price1 to price5) I need to write the PHP code for the mySQL query that brings back the ids numbers for the products by the cheapest. So in the attached screenshot it would be ID 6 as it has price3 as ?1.01. Then it would bring back ID 3 as price1 is ?17.00 then ID4 as the next cheapest price is ?17.99 (price1) Is this possible? Many thanks for your help.
  14. Hi there I have restructured the database to have the 5 prices in the same table as the rest of the data. Is there anyway I can search multiple rows for the lowest value across the 5 columns and then show the results in this order? I have attached my database. Regards Pete
  15. Hi there Thanks for your help so far! Basically, I need to get my product IDs in order of price. So that I can query the database again to get the product information. If you look at my database, you can see that the prices can be sorted by value ascending. I need to then group the product IDs in the correct order so I can then query the database again for the full information. Many thanks Pete
×
×
  • 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.