RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Ralph Guzman
I agree with Curt, use mySQL to get the sum of 'sess_itemsize' then
divide the result by size per disk to get quantity. So your function
should look something like this:

function cart_cdqty()
{

$query = SELECT SUM(sess_itemsize) AS total_size 
  FROM sessions 
  WHERE sess_id = .$_COOKIE['SID'].;

$result = mysql_query($query);

if($row = mysql_fetch_array($result))
{
   $n = $row['total_size'];
   $x = ceil( $n / 690.0 );
   
   $cart_cdqty = array(
   'quantity' = '$x',
   'total_size' = '$n',
   );
   
   return $cart_cdqty;
} else {
   return false;
}

}

Then all you do is call the function like this:

if(!$cdqty = cart_cdqty())
{
   print 'no items found in your shopping cart';
} else {
   print 'Total Size:' . $cdqty['quantity'] . 'BR';
   print 'Total CDs:' .  $cdqty['total_size'] . 'MBs BR';
}

I have not tested this but it should work.

Ralph

-Original Message-
From: Cesar Aracena [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2003 8:54 PM
To: 'Ralph Guzman'; [EMAIL PROTECTED]
Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
Importance: High
Sensitivity: Confidential

Ok. Here you have the entire function to see how many CD's the order
will contain:

function cart_cdqty()
{
$query = SELECT * FROM sessions WHERE sess_sid =
.$_COOKIE['SID'].;
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

$x = 0;
$n = 0;

for ($y = 0; $y  $num_rows; $y++)
{
$row = mysql_fetch_array($result);
$n = $n + $row[sess_itemsize];
}

if ($n  0 AND $n = 690.0) { 
$x = 1;
} elseif ($n  690.1 AND $n = 1380.0) { 
$x = 2;
} elseif ($n  1380.1 AND $n = 2070.0) { 
$x = 3;
} elseif ($n  2070.1 AND $n = 2760.0) { 
$x = 4;
} elseif ($n  2760.1 AND $n = 3450.0) { 
$x = 5;
}

return $x;
}

Pretty long if someone wants to order 17MBs don't you agree?

Thanks for this,

Cesar Aracena

 
 No, that sounds about right.
 
 So your table should have the following fields:
 
 customer_session_id, item_id, quantity, final_price
 
 so then all you have to do is query this table looking for all items
in
 customers shopping cart.
 
 I am not quite sure how you are going about calculating orders in
 customer's basket. You said you wrote a function with multiple IF
 statements, can you show me the code for this function so that I can
get
 a better idea of what you are currently doing?
 
 
 -Original Message-
 From: Cesar Aracena [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 8:38 PM
 To: 'Ralph Guzman'; [EMAIL PROTECTED]
 Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
 Importance: High
 Sensitivity: Confidential
 
 Using a cookie (I know, I know...) I plant a cookie in the visitor's
 browser when he opens the site with a random generated number which
 expires when the browser(s) is closed. With that SID, PHP stores the
 orders (one per line) into a sessions table in MySQL each with the
 itemID. Is it fine or am I too messy?
 
 TXS,
 
 Cesar Aracena
 
 
  How are you keeping track of items added being added to the shopping
  cart?
 
  -Original Message-
  From: Cesar Aracena [mailto:[EMAIL PROTECTED]
  Sent: Monday, August 18, 2003 7:55 PM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Delimiter WITHOUT lots of IF's
  Importance: High
  Sensitivity: Confidential
 
  Hi all,
 
  I need to create an automatic process for visitors who are adding
 items
  into a shopping cart, be able to see how many MBs and how many CDs
 will
  the order have.
 
  From this site, visitors will be able to choose one ore more
software
  products from a list of hundreds. I want them to check the cart to
see
  something like:
 
  Total size: 872,43 MBs
  Total CDs: 2
  Total price: $XXX,XX
 
  Now, I developed a decision function that works with a lot of IF
  statements, but I only calculated a max o 6 CDs (690,00 MBs max. per
  CD), but I want to be able to make this automatically... Can someone
  help me with this?
 
  BTW, Using PHP 4+ and MySQL 3+.
 
  Thanks in advanced,
 
  Cesar Aracena
  www.icaam.com.ar
 
  Note: The information inside this message and also in the attached
 files
  might be confidential. If you are not the desired receptor or the
 person
  responsible of delivering the message, we notify you that it's copy,
  distribution, keep or illegal use of the information it has it's
  prohibited. Therefore we ask you to notify the sender by replying
this
  message immediately and then delete it from your computer.
 
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net

RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Cesar Aracena
Thanks Curt AND Ralph,

This makes it all a lot more clear and easy to understand. And yes, it
makes sense. I'll try it now and see what happens.

What I've never seen before is what you did with:

if($row = mysql_fetch_array($result))

that made me go LOL!!!

Thanks in advanced,

Cesar Aracena
www.icaam.com.ar

 
 I agree with Curt, use mySQL to get the sum of 'sess_itemsize' then
 divide the result by size per disk to get quantity. So your function
 should look something like this:
 
 function cart_cdqty()
 {
 
 $query = SELECT SUM(sess_itemsize) AS total_size
   FROM sessions
   WHERE sess_id = .$_COOKIE['SID'].;
 
 $result = mysql_query($query);
 
 if($row = mysql_fetch_array($result))
 {
$n = $row['total_size'];
$x = ceil( $n / 690.0 );
 
$cart_cdqty = array(
'quantity' = '$x',
'total_size' = '$n',
);
 
return $cart_cdqty;
 } else {
return false;
 }
 
 }
 
 Then all you do is call the function like this:
 
 if(!$cdqty = cart_cdqty())
 {
print 'no items found in your shopping cart';
 } else {
print 'Total Size:' . $cdqty['quantity'] . 'BR';
print 'Total CDs:' .  $cdqty['total_size'] . 'MBs BR';
 }
 
 I have not tested this but it should work.
 
 Ralph
 
 -Original Message-
 From: Cesar Aracena [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 8:54 PM
 To: 'Ralph Guzman'; [EMAIL PROTECTED]
 Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
 Importance: High
 Sensitivity: Confidential
 
 Ok. Here you have the entire function to see how many CD's the order
 will contain:
 
 function cart_cdqty()
 {
   $query = SELECT * FROM sessions WHERE sess_sid =
 .$_COOKIE['SID'].;
   $result = mysql_query($query);
   $num_rows = mysql_num_rows($result);
 
   $x = 0;
   $n = 0;
 
   for ($y = 0; $y  $num_rows; $y++)
   {
   $row = mysql_fetch_array($result);
   $n = $n + $row[sess_itemsize];
   }
 
   if ($n  0 AND $n = 690.0) {
   $x = 1;
   } elseif ($n  690.1 AND $n = 1380.0) {
   $x = 2;
   } elseif ($n  1380.1 AND $n = 2070.0) {
   $x = 3;
   } elseif ($n  2070.1 AND $n = 2760.0) {
   $x = 4;
   } elseif ($n  2760.1 AND $n = 3450.0) {
   $x = 5;
   }
 
   return $x;
 }
 
 Pretty long if someone wants to order 17MBs don't you agree?
 
 Thanks for this,
 
 Cesar Aracena
 
 
  No, that sounds about right.
 
  So your table should have the following fields:
 
  customer_session_id, item_id, quantity, final_price
 
  so then all you have to do is query this table looking for all items
 in
  customers shopping cart.
 
  I am not quite sure how you are going about calculating orders in
  customer's basket. You said you wrote a function with multiple IF
  statements, can you show me the code for this function so that I can
 get
  a better idea of what you are currently doing?
 
 
  -Original Message-
  From: Cesar Aracena [mailto:[EMAIL PROTECTED]
  Sent: Monday, August 18, 2003 8:38 PM
  To: 'Ralph Guzman'; [EMAIL PROTECTED]
  Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
  Importance: High
  Sensitivity: Confidential
 
  Using a cookie (I know, I know...) I plant a cookie in the visitor's
  browser when he opens the site with a random generated number which
  expires when the browser(s) is closed. With that SID, PHP stores the
  orders (one per line) into a sessions table in MySQL each with the
  itemID. Is it fine or am I too messy?
 
  TXS,
 
  Cesar Aracena
 
  
   How are you keeping track of items added being added to the
shopping
   cart?
  
   -Original Message-
   From: Cesar Aracena [mailto:[EMAIL PROTECTED]
   Sent: Monday, August 18, 2003 7:55 PM
   To: [EMAIL PROTECTED]
   Subject: [PHP] Delimiter WITHOUT lots of IF's
   Importance: High
   Sensitivity: Confidential
  
   Hi all,
  
   I need to create an automatic process for visitors who are adding
  items
   into a shopping cart, be able to see how many MBs and how many CDs
  will
   the order have.
  
   From this site, visitors will be able to choose one ore more
 software
   products from a list of hundreds. I want them to check the cart to
 see
   something like:
  
   Total size: 872,43 MBs
   Total CDs: 2
   Total price: $XXX,XX
  
   Now, I developed a decision function that works with a lot of IF
   statements, but I only calculated a max o 6 CDs (690,00 MBs max.
per
   CD), but I want to be able to make this automatically... Can
someone
   help me with this?
  
   BTW, Using PHP 4+ and MySQL 3+.
  
   Thanks in advanced,
  
   Cesar Aracena
   www.icaam.com.ar
  
   Note: The information inside this message and also in the attached
  files
   might be confidential. If you are not the desired receptor or the
  person
   responsible of delivering the message, we notify you that it's
copy,
   distribution, keep or illegal use

RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Ralph Guzman
Actually, I missed a few things on that function. It should look like
this:

function cart_cdqty()
{

$query = SELECT SUM(sess_itemsize) AS total_size 
  FROM sessions 
  WHERE sess_id = .$_COOKIE['SID'].;

$result = mysql_query($query);

if(!$row = mysql_fetch_array($result))
{
   return false;
} else {
   $n = $row['total_size'];
   $x = ceil( $n / 690.0 );
   
   $cart_cdqty = array(
   'quantity' = $x,
   'total_size' = $n
   );
   
   return $cart_cdqty;
} 

}


-Original Message-
From: Ralph Guzman [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2003 11:41 PM
To: 'Cesar Aracena'; [EMAIL PROTECTED]
Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
Sensitivity: Confidential

I agree with Curt, use mySQL to get the sum of 'sess_itemsize' then
divide the result by size per disk to get quantity. So your function
should look something like this:

function cart_cdqty()
{

$query = SELECT SUM(sess_itemsize) AS total_size 
  FROM sessions 
  WHERE sess_id = .$_COOKIE['SID'].;

$result = mysql_query($query);

if($row = mysql_fetch_array($result))
{
   $n = $row['total_size'];
   $x = ceil( $n / 690.0 );
   
   $cart_cdqty = array(
   'quantity' = '$x',
   'total_size' = '$n',
   );
   
   return $cart_cdqty;
} else {
   return false;
}

}

Then all you do is call the function like this:

if(!$cdqty = cart_cdqty())
{
   print 'no items found in your shopping cart';
} else {
   print 'Total Size:' . $cdqty['quantity'] . 'BR';
   print 'Total CDs:' .  $cdqty['total_size'] . 'MBs BR';
}

I have not tested this but it should work.

Ralph





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Cesar Aracena
Ralph, I tested the function below but the result at the page is:

CD Quantity: Array

and not the CD quantity according to file size... Why is the array there
and what it is supposed to be called with to give one or another result?

Thanks,

Cesar Aracena
www.icaam.com.ar

 
 Actually, I missed a few things on that function. It should look like
 this:
 
 function cart_cdqty()
 {
 
 $query = SELECT SUM(sess_itemsize) AS total_size
   FROM sessions
   WHERE sess_id = .$_COOKIE['SID'].;
 
 $result = mysql_query($query);
 
 if(!$row = mysql_fetch_array($result))
 {
return false;
 } else {
$n = $row['total_size'];
$x = ceil( $n / 690.0 );
 
$cart_cdqty = array(
'quantity' = $x,
'total_size' = $n
);
 
return $cart_cdqty;
 }
 
 }
 
 
 -Original Message-
 From: Ralph Guzman [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 11:41 PM
 To: 'Cesar Aracena'; [EMAIL PROTECTED]
 Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
 Sensitivity: Confidential
 
 I agree with Curt, use mySQL to get the sum of 'sess_itemsize' then
 divide the result by size per disk to get quantity. So your function
 should look something like this:
 
 function cart_cdqty()
 {
 
 $query = SELECT SUM(sess_itemsize) AS total_size
   FROM sessions
   WHERE sess_id = .$_COOKIE['SID'].;
 
 $result = mysql_query($query);
 
 if($row = mysql_fetch_array($result))
 {
$n = $row['total_size'];
$x = ceil( $n / 690.0 );
 
$cart_cdqty = array(
'quantity' = '$x',
'total_size' = '$n',
);
 
return $cart_cdqty;
 } else {
return false;
 }
 
 }
 
 Then all you do is call the function like this:
 
 if(!$cdqty = cart_cdqty())
 {
print 'no items found in your shopping cart';
 } else {
print 'Total Size:' . $cdqty['quantity'] . 'BR';
print 'Total CDs:' .  $cdqty['total_size'] . 'MBs BR';
 }
 
 I have not tested this but it should work.
 
 Ralph
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Chris W. Parker
Cesar Aracena mailto:[EMAIL PROTECTED]
on Tuesday, August 19, 2003 10:18 AM said:

 Sensitivity: Confidential

Oh really?

 and not the CD quantity according to file size... Why is the array
 there and what it is supposed to be called with to give one or
 another result? 

Pay close attention to this part:

$cart_cdqty = array(
'quantity' = $x,
'total_size' = $n
);
 
return $cart_cdqty;

That means it's returning an array. one index is called 'quantity' and
the other is called 'total_size'.


$qty = function(input);

echo quantity is .$qty['quantity'];


hth,
chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Cesar Aracena
Ok, That's logical, but the thing is that even $x and $n are empty, as
if the result would give a hole bunch of zeros (but it isn't).

Could there be an error in the query or somewhere around that we are all
missing?

Thanks,

Cesar

 function cart_cdqty()
 {
 
 $query = SELECT SUM(sess_itemsize) AS total_size
   FROM sessions
   WHERE sess_id = .$_COOKIE['SID'].;
 
 $result = mysql_query($query);
 
 if(!$row = mysql_fetch_array($result))
 {
return false;
 } else {
$n = $row['total_size'];
$x = ceil( $n / 690.0 );
 
$cart_cdqty = array(
'quantity' = $x,
'total_size' = $n
);
 
return $cart_cdqty;
 }
 
 }



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Cesar Aracena
 
 So it's not returning any results?
 
 What happens when you do the following...
 
  } else {
 $n = $row['total_size'];
   echo :$n:;
 
 Put that echo statement in your code and see what happens.
 
 If you've already done this and it prints :: (as opposed to :0: which
 would indicate a value of zero) then you're sql query is not correct
or
 there are just no rows that match what you're looking for.
 
[Cesar Aracena] 

It does print 0 so I guess something must be wrong somewhere else. My
guess is that $row['total_size'] is not fetching anything. Shouldn't the
function contain a mysql_fetch_array somewhere?

Thanks

Cesar



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-19 Thread Chris W. Parker
Cesar Aracena mailto:[EMAIL PROTECTED]
on Tuesday, August 19, 2003 11:38 AM said:

 Importance: High
 Sensitivity: Confidential

Is this being done by your server or by you?

 It does print 0 so I guess something must be wrong somewhere else. My
 guess is that $row['total_size'] is not fetching anything. Shouldn't
 the function contain a mysql_fetch_array somewhere?

Ok. If it prints zero that means it's (a) your SQL query works, (b) your
retrieving the value correctly from the $result.

$row['total_size'] seems to be working as expected. If it wasn't working
correctly it'd probably print Array or something.

You're next option would be to try print_r();


echo pre;
print_r($row);
echo /pre;

That will show you exactly what's in $row.



c.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's :: SOLVED ::

2003-08-19 Thread Cesar Aracena
 
  Importance: High
  Sensitivity: Confidential
 
 Is this being done by your server or by you?
 

By me, because of my Company's policies and requirements. Sorry if it
bothers anyone :)

  It does print 0 so I guess something must be wrong somewhere else.
My
  guess is that $row['total_size'] is not fetching anything. Shouldn't
  the function contain a mysql_fetch_array somewhere?
 
 Ok. If it prints zero that means it's (a) your SQL query works, (b)
your
 retrieving the value correctly from the $result.

There was an error actually in the query, that was passed while copying
one of Ralph's answers. Just a Typo that I didn't saw earlier.

 
 $row['total_size'] seems to be working as expected. If it wasn't
working
 correctly it'd probably print Array or something.
 
 You're next option would be to try print_r();
 
 
 echo pre;
 print_r($row);
 echo /pre;
 
 That will show you exactly what's in $row.
 

Thanks to everyone who helped me with this.

Cesar




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-18 Thread Ralph Guzman
How are you keeping track of items added being added to the shopping
cart? 

-Original Message-
From: Cesar Aracena [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2003 7:55 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Delimiter WITHOUT lots of IF's
Importance: High
Sensitivity: Confidential

Hi all,

I need to create an automatic process for visitors who are adding items
into a shopping cart, be able to see how many MBs and how many CDs will
the order have.

From this site, visitors will be able to choose one ore more software
products from a list of hundreds. I want them to check the cart to see
something like:

Total size: 872,43 MBs
Total CDs: 2
Total price: $XXX,XX

Now, I developed a decision function that works with a lot of IF
statements, but I only calculated a max o 6 CDs (690,00 MBs max. per
CD), but I want to be able to make this automatically... Can someone
help me with this?

BTW, Using PHP 4+ and MySQL 3+.

Thanks in advanced,

Cesar Aracena
www.icaam.com.ar

Note: The information inside this message and also in the attached files
might be confidential. If you are not the desired receptor or the person
responsible of delivering the message, we notify you that it's copy,
distribution, keep or illegal use of the information it has it's
prohibited. Therefore we ask you to notify the sender by replying this
message immediately and then delete it from your computer.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-18 Thread Ralph Guzman
How are you keeping track of items added being added to the shopping
cart? 

-Original Message-
From: Cesar Aracena [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2003 7:55 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Delimiter WITHOUT lots of IF's
Importance: High
Sensitivity: Confidential

Hi all,

I need to create an automatic process for visitors who are adding items
into a shopping cart, be able to see how many MBs and how many CDs will
the order have.

From this site, visitors will be able to choose one ore more software
products from a list of hundreds. I want them to check the cart to see
something like:

Total size: 872,43 MBs
Total CDs: 2
Total price: $XXX,XX

Now, I developed a decision function that works with a lot of IF
statements, but I only calculated a max o 6 CDs (690,00 MBs max. per
CD), but I want to be able to make this automatically... Can someone
help me with this?

BTW, Using PHP 4+ and MySQL 3+.

Thanks in advanced,

Cesar Aracena
www.icaam.com.ar

Note: The information inside this message and also in the attached files
might be confidential. If you are not the desired receptor or the person
responsible of delivering the message, we notify you that it's copy,
distribution, keep or illegal use of the information it has it's
prohibited. Therefore we ask you to notify the sender by replying this
message immediately and then delete it from your computer.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-18 Thread Cesar Aracena
Using a cookie (I know, I know...) I plant a cookie in the visitor's
browser when he opens the site with a random generated number which
expires when the browser(s) is closed. With that SID, PHP stores the
orders (one per line) into a sessions table in MySQL each with the
itemID. Is it fine or am I too messy?

TXS,

Cesar Aracena

 
 How are you keeping track of items added being added to the shopping
 cart?
 
 -Original Message-
 From: Cesar Aracena [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 7:55 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Delimiter WITHOUT lots of IF's
 Importance: High
 Sensitivity: Confidential
 
 Hi all,
 
 I need to create an automatic process for visitors who are adding
items
 into a shopping cart, be able to see how many MBs and how many CDs
will
 the order have.
 
 From this site, visitors will be able to choose one ore more software
 products from a list of hundreds. I want them to check the cart to see
 something like:
 
 Total size: 872,43 MBs
 Total CDs: 2
 Total price: $XXX,XX
 
 Now, I developed a decision function that works with a lot of IF
 statements, but I only calculated a max o 6 CDs (690,00 MBs max. per
 CD), but I want to be able to make this automatically... Can someone
 help me with this?
 
 BTW, Using PHP 4+ and MySQL 3+.
 
 Thanks in advanced,
 
 Cesar Aracena
 www.icaam.com.ar
 
 Note: The information inside this message and also in the attached
files
 might be confidential. If you are not the desired receptor or the
person
 responsible of delivering the message, we notify you that it's copy,
 distribution, keep or illegal use of the information it has it's
 prohibited. Therefore we ask you to notify the sender by replying this
 message immediately and then delete it from your computer.
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-18 Thread Ralph Guzman
No, that sounds about right. 

So your table should have the following fields:

customer_session_id, item_id, quantity, final_price

so then all you have to do is query this table looking for all items in
customers shopping cart. 

I am not quite sure how you are going about calculating orders in
customer's basket. You said you wrote a function with multiple IF
statements, can you show me the code for this function so that I can get
a better idea of what you are currently doing?


-Original Message-
From: Cesar Aracena [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 18, 2003 8:38 PM
To: 'Ralph Guzman'; [EMAIL PROTECTED]
Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
Importance: High
Sensitivity: Confidential

Using a cookie (I know, I know...) I plant a cookie in the visitor's
browser when he opens the site with a random generated number which
expires when the browser(s) is closed. With that SID, PHP stores the
orders (one per line) into a sessions table in MySQL each with the
itemID. Is it fine or am I too messy?

TXS,

Cesar Aracena

 
 How are you keeping track of items added being added to the shopping
 cart?
 
 -Original Message-
 From: Cesar Aracena [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 7:55 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Delimiter WITHOUT lots of IF's
 Importance: High
 Sensitivity: Confidential
 
 Hi all,
 
 I need to create an automatic process for visitors who are adding
items
 into a shopping cart, be able to see how many MBs and how many CDs
will
 the order have.
 
 From this site, visitors will be able to choose one ore more software
 products from a list of hundreds. I want them to check the cart to see
 something like:
 
 Total size: 872,43 MBs
 Total CDs: 2
 Total price: $XXX,XX
 
 Now, I developed a decision function that works with a lot of IF
 statements, but I only calculated a max o 6 CDs (690,00 MBs max. per
 CD), but I want to be able to make this automatically... Can someone
 help me with this?
 
 BTW, Using PHP 4+ and MySQL 3+.
 
 Thanks in advanced,
 
 Cesar Aracena
 www.icaam.com.ar
 
 Note: The information inside this message and also in the attached
files
 might be confidential. If you are not the desired receptor or the
person
 responsible of delivering the message, we notify you that it's copy,
 distribution, keep or illegal use of the information it has it's
 prohibited. Therefore we ask you to notify the sender by replying this
 message immediately and then delete it from your computer.
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Delimiter WITHOUT lots of IF's

2003-08-18 Thread Cesar Aracena
Ok. Here you have the entire function to see how many CD's the order
will contain:

function cart_cdqty()
{
$query = SELECT * FROM sessions WHERE sess_sid =
.$_COOKIE['SID'].;
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

$x = 0;
$n = 0;

for ($y = 0; $y  $num_rows; $y++)
{
$row = mysql_fetch_array($result);
$n = $n + $row[sess_itemsize];
}

if ($n  0 AND $n = 690.0) { 
$x = 1;
} elseif ($n  690.1 AND $n = 1380.0) { 
$x = 2;
} elseif ($n  1380.1 AND $n = 2070.0) { 
$x = 3;
} elseif ($n  2070.1 AND $n = 2760.0) { 
$x = 4;
} elseif ($n  2760.1 AND $n = 3450.0) { 
$x = 5;
}

return $x;
}

Pretty long if someone wants to order 17MBs don't you agree?

Thanks for this,

Cesar Aracena

 
 No, that sounds about right.
 
 So your table should have the following fields:
 
 customer_session_id, item_id, quantity, final_price
 
 so then all you have to do is query this table looking for all items
in
 customers shopping cart.
 
 I am not quite sure how you are going about calculating orders in
 customer's basket. You said you wrote a function with multiple IF
 statements, can you show me the code for this function so that I can
get
 a better idea of what you are currently doing?
 
 
 -Original Message-
 From: Cesar Aracena [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 8:38 PM
 To: 'Ralph Guzman'; [EMAIL PROTECTED]
 Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
 Importance: High
 Sensitivity: Confidential
 
 Using a cookie (I know, I know...) I plant a cookie in the visitor's
 browser when he opens the site with a random generated number which
 expires when the browser(s) is closed. With that SID, PHP stores the
 orders (one per line) into a sessions table in MySQL each with the
 itemID. Is it fine or am I too messy?
 
 TXS,
 
 Cesar Aracena
 
 
  How are you keeping track of items added being added to the shopping
  cart?
 
  -Original Message-
  From: Cesar Aracena [mailto:[EMAIL PROTECTED]
  Sent: Monday, August 18, 2003 7:55 PM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Delimiter WITHOUT lots of IF's
  Importance: High
  Sensitivity: Confidential
 
  Hi all,
 
  I need to create an automatic process for visitors who are adding
 items
  into a shopping cart, be able to see how many MBs and how many CDs
 will
  the order have.
 
  From this site, visitors will be able to choose one ore more
software
  products from a list of hundreds. I want them to check the cart to
see
  something like:
 
  Total size: 872,43 MBs
  Total CDs: 2
  Total price: $XXX,XX
 
  Now, I developed a decision function that works with a lot of IF
  statements, but I only calculated a max o 6 CDs (690,00 MBs max. per
  CD), but I want to be able to make this automatically... Can someone
  help me with this?
 
  BTW, Using PHP 4+ and MySQL 3+.
 
  Thanks in advanced,
 
  Cesar Aracena
  www.icaam.com.ar
 
  Note: The information inside this message and also in the attached
 files
  might be confidential. If you are not the desired receptor or the
 person
  responsible of delivering the message, we notify you that it's copy,
  distribution, keep or illegal use of the information it has it's
  prohibited. Therefore we ask you to notify the sender by replying
this
  message immediately and then delete it from your computer.
 
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Delimiter WITHOUT lots of IF's

2003-08-18 Thread Curt Zirzow
* Thus wrote Cesar Aracena ([EMAIL PROTECTED]):
 Ok. Here you have the entire function to see how many CD's the order
 will contain:
 
 function cart_cdqty()
 {
   $query = SELECT * FROM sessions WHERE sess_sid =
 .$_COOKIE['SID'].;
   $result = mysql_query($query);
   $num_rows = mysql_num_rows($result);
   
   $x = 0;
   $n = 0;
   
   for ($y = 0; $y  $num_rows; $y++)
   {
   $row = mysql_fetch_array($result);
   $n = $n + $row[sess_itemsize];
   }

For one, sql can handle this for you. much faster too, I might add.
just do something like:

  select sum(sess_itemsize) from sessions where sess_id = ...
  
  ...

  $result = mysql_query($query);
  list($n) = mysql_fetch_row($result);

   
   if ($n  0 AND $n = 690.0) { 
   $x = 1;
   } elseif ($n  690.1 AND $n = 1380.0) { 
   $x = 2;
   } elseif ($n  1380.1 AND $n = 2070.0) { 
   $x = 3;
   } elseif ($n  2070.1 AND $n = 2760.0) { 
   $x = 4;
   } elseif ($n  2760.1 AND $n = 3450.0) { 
   $x = 5;
   }

A simple division of the size per disk will give you the qty:
  $x = ceil( $n / 690.0 );

Now it wont be so bad if someone is ording 30 disks worth... i'd
hate to see that if statment not to mention write it :)

You might want to check for $x  0 cause I don't think the customer
will be happy if he has to pay you to send you his disks.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php