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 ??? Link to comment https://forums.phpfreaks.com/topic/19932-while-loop-table-read-discount/ 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. Link to comment https://forums.phpfreaks.com/topic/19932-while-loop-table-read-discount/#findComment-87304 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 :) Link to comment https://forums.phpfreaks.com/topic/19932-while-loop-table-read-discount/#findComment-87319 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...) Link to comment https://forums.phpfreaks.com/topic/19932-while-loop-table-read-discount/#findComment-87372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.