Jump to content

while loop table, read discount


alpine

Recommended Posts

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;20
5601;15

etc...

or is it possible to save a file as an two dimentional array like

array(5600 => 20, 5601 => 15 ......);

...havent tested to see if it works though...


WHATS FASTEST to retrieve datas ???

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.