alpine Posted September 6, 2006 Share Posted September 6, 2006 I have a table with items that i want to match up with the price discount.Currently i have the discounts stored in a separate table, but as the amount of users grows i cannot add one table with discount for each customer. Thats why i must find another solution.illustrating the items table:--------------------------------item_id | discount_code | etc....--------------------------------1 | 5600 |--------------------------------and the discount goes like------------------------- discount_code | discount------------------------- 5600 | 20-------------------------I am thinking about writing discount codes and discount values to a discount file (.txt or whatever) for each customer and read this to match each item upon request. I am however concerned about how to do this the right way so its still very fast to find/read while looping the items table and showing results.Any ideas? Just making a file like:5600;205601;15etc...or is it possible to save a file as an two dimentional array likearray(5600 => 20, 5601 => 15 ......);...havent tested to see if it works though...WHATS FASTEST to retrieve datas ??? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 6, 2006 Share Posted September 6, 2006 [code]SELECT i.*,d.* FROM items AS i LEFT JOIN discounts AS d ON i.discount_code=d.discount_code;[/code]This will select the items with the discount. Then use mysql_fetch_assoc() in a while loop to get run through all the items. Quote Link to comment Share on other sites More sharing options...
alpine Posted September 6, 2006 Author Share Posted September 6, 2006 thanx, but i'm seeking the fastest way to retrieve a match from a file - not a table, already have that :) Quote Link to comment Share on other sites More sharing options...
alpine Posted September 6, 2006 Author Share Posted September 6, 2006 ok - i've tested and found this so far:[color=green]<?php$dir_path = "/www/www.what.net/dir/dir/dir";$file = $dir_path . "/disc.txt";$dfile = file_get_contents($file);$disklines = explode("\n", $dfile);$arr = array();foreach ($disklines as $line){$line = explode(";", $line);$disc_code = $line[0];$disc = $line[1];$arr[$disc_code] = $disc;//echo "<p r e>";//print_r($arr);//echo "</ p r e>";}// $query = mysql_query(" blah... ");// while($row = mysql_fetch_array($query){$discount_code = $row["discount_code"];if (array_key_exists($discount_code, $arr)){$disc = $arr[$disc_code];}}?>[/color]seems fast and ok... ? any improvements out there ?? (...always seem to be...) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.