[PHP-DB] error on count()

2004-09-07 Thread Sancerni Veronica
hello, this is problably newbie question, but I can not understand why my count() 
function doesn't work. I need to count how many items has a determinated customer 
ordered ever.
 
1. I tired to get the array like this:
 $una = $check[uname];
function orderquantity ($una) {
  $pss = mysql_query(SELECT OID FROM orders WHERE una = '.trim($una).') or die 
(mysql_error(Query error on Order search));
  while($pisao=mysql_fetch_array($pss)) {
  return count($pisao);
  }
}
$okuan = orderquantity();
 
2. and like this:
 $una = $check[uname];
function orderquantity ($una) {
  $pss = mysql_query(SELECT OID FROM orders WHERE una = '.trim($una).') or die 
(mysql_error(Query error on Order search));
   return count($pss);
}
okuan = orderquantity();
 
None of them gave me a valid value, is it because the OID is an int value?


-
Créez gratuitement votre Yahoo! Mail avec 100 Mo de stockage !
Créez votre Yahoo! Mail

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour 
dialoguer instantanément avec vos amis.Téléchargez GRATUITEMENT ici !

Re: [PHP-DB] error on count()

2004-09-07 Thread Peter Ellis
You need to pass the functions a variable to work with because you've
specified parameters.  Try:

$okuan = orderquantity($una);

Ditto for the other function call.
-- 
Peter Ellis - [EMAIL PROTECTED]
Web Design and Development Consultant
naturalaxis | http://www.naturalaxis.com/

On Tue, 2004-09-07 at 13:09 +0200, Sancerni Veronica wrote:
 hello, this is problably newbie question, but I can not understand why my count() 
 function doesn't work. I need to count how many items has a determinated customer 
 ordered ever.
  
 1. I tired to get the array like this:
  $una = $check[uname];
 function orderquantity ($una) {
   $pss = mysql_query(SELECT OID FROM orders WHERE una = '.trim($una).') or die 
 (mysql_error(Query error on Order search));
   while($pisao=mysql_fetch_array($pss)) {
   return count($pisao);
   }
 }
 $okuan = orderquantity();
  
 2. and like this:
  $una = $check[uname];
 function orderquantity ($una) {
   $pss = mysql_query(SELECT OID FROM orders WHERE una = '.trim($una).') or die 
 (mysql_error(Query error on Order search));
return count($pss);
 }
 okuan = orderquantity();
  
 None of them gave me a valid value, is it because the OID is an int value?
 
   
 -
 Crez gratuitement votre Yahoo! Mail avec 100 Mo de stockage !
 Crez votre Yahoo! Mail
 
 Le nouveau Yahoo! Messenger est arriv ! Dcouvrez toutes les nouveauts pour 
 dialoguer instantanment avec vos amis.Tlchargez GRATUITEMENT ici !

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



Re: [PHP-DB] error on count()

2004-09-07 Thread zareef ahmed
  1. I tired to get the array like this:
   $una = $check[uname];
  function orderquantity ($una) {
$pss = mysql_query(SELECT OID FROM orders WHERE
 una = '.trim($una).') or die (mysql_error(Query
 error on Order search));
while($pisao=mysql_fetch_array($pss)) {
return count($pisao);
}
  }
  $okuan = orderquantity();
   

first of all you should pass a variable to the
function.

Second :: function will just return one in any
condition because $pisao is the array of return fields
in the particular row. you should use
mysql_num_rows($pss).

no need of mysql_fetch_array()

just return mysql_num_rows{$pss) after executing
query.


Third , I think it is best to use sensible variable
like $query, $result, $row etc., well its depends on
you.

zareef ahmed 



=
Homepage :: http://www.zasaifi.com



___
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush

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