
petenaylor
Members-
Posts
165 -
Joined
-
Last visited
Everything posted by petenaylor
-
Sorted! Thanks for your help folks!
-
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.
-
Hi there Yes that's correct I just need to echo out the array key itself.
-
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
-
I think it is becuase the prices are stored as a varchar, do they need storing as decimal?
-
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!
-
Hi there, the database is taking care of the relationship.
-
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
-
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
-
That's it! That's all I needed, thanks for your help!
-
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
-
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.
-
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.
-
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
-
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
-
Hi all I have a table which is attached that has prices and a product_id. What I need to do is firstly, order by the price and then group by the product_id. I need to know how to write the mySQL query to do this. I can only group by and then sort by. Many thanks for your help. Pete
-
Hi all I need to write a mySQL query that selects all from one table where there is not the instance in more than one field in another table. The query I have so far is: mysql_query (" SELECT * FROM text_positions where position not in (select logo_position from shop_basket ) ORDER BY position ASC ") or die (mysql_error()); Which works great, but the position could also be in the text_position on the shop_basket table. How can I add this into my query? There is 5 possible field I need to check in the shop_basket table. Many thanks Pete
-
Thanks for your help. I have now done print_r($_POST['portfolioids']); Which gives me : Array ( [19] => 8 [7] => 8 [8] => 8 [18] => 8 [20] => 8 [14] => 8 [9] => 8 [11] => 8 ) as I only ticked these boxes. I now need to write a loop to add these into my mySQL database. Can I do a for each on just these post values?
-
Hi all I am trying to write a piece of code that grabs post values. The form looks like this: Menus <input name="tagid" value="1" type="hidden" /> <input name="portfolioid" value="8" type="hidden" /> <input name="check_1" type="checkbox" value="1" /> Basically there will be a variable number of tick boxes. I need to grab the values that have the checkbox value of 1 and insert them into a mySQL database. I am already grabbing some other data from the form. How do I assign the input_name to a string in a loop? Many thanks Pete