Fwd: Re: [PHP-DB] need help with foreach()

2003-03-10 Thread David Rice
Here is the complete function I am using.
I returned, for testing i commented out the foreach loop and returned 
$staff, then $tips both arrays returned NULL when i did a 
var_dump(pointvalue($startdate));

can anyone see how this could be solved?

Cheers,
dave
==
function pointvalue($start){
	$query = SELECT * FROM Tips WHERE date = $start and date = ($start + 
INTERVAL 6 DAY) ;
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result)){
	$date = $row[Date];
		$tips[$date] = $row[TotalTips];
	}
	$query = SELECT * FROM Rota WHERE date = $start and date = ($start + 
INTERVAL 6 DAY) ;
	$result = mysql_query($query);
	while ($row = mysql_fetch_array($result)){
		$date = $row[Date];
		if (isset($staff[$date])){

			$staff[$date] = $staff[$date] + 1;

}
else{
$staff[$date] = 1;
}
}
return $staff;
}
_
Use MSN Messenger to send music and pics to your friends 
http://messenger.msn.co.uk

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


Re: Fwd: Re: [PHP-DB] need help with foreach()

2003-03-10 Thread Jason Wong
On Monday 10 March 2003 17:56, David Rice wrote:
 Here is the complete function I am using.
 I returned, for testing i commented out the foreach loop and returned
 $staff, then $tips both arrays returned NULL when i did a
 var_dump(pointvalue($startdate));

I haven't been following this thread so I'm not sure what your objective is. 
But ...


 function pointvalue($start){
   $query = SELECT * FROM Tips WHERE date = $start and date = ($start +
 INTERVAL 6 DAY) ;
   $result = mysql_query($query);
   while($row = mysql_fetch_array($result)){
   $date = $row[Date];

You should really be using:

   $date = $row['Date'];

Also what is $date supposed to be storing? Each iteration of the while-loop 
it's being overwritten with the 'latest' date.

   $tips[$date] = $row[TotalTips];

As above you should put single-quotes around your array subscripts.

   }
   $query = SELECT * FROM Rota WHERE date = $start and date = ($start +
 INTERVAL 6 DAY) ;
   $result = mysql_query($query);
   while ($row = mysql_fetch_array($result)){
   $date = $row[Date];

Again, see above comments.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
You can observe a lot just by watching.  -- Yogi Berra
*/


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



[PHP-DB] need help with foreach()

2003-03-09 Thread David Rice
Okay, i have two arrays, $tips and $staff

$tips has a key date (which is the date of the first day of the week, the 
second result in the array has the key of the second day of the week etc... 
) and the value is a floating point decimal.

$staff also has a key date and the value is an integer, the number of 
staff working in one day.

To find out the ammount of tips every staff member is to get we have to 
divide the value of $tips by the value of $staff (when the dates are the 
same)

what i was trying  to get this to work is below,

any help would be great,
cheers
dave
=
foreach($tips as $key = $value){

		$pointvalue[$key] = $value / current($staff) ;

next($staff);
}
_
Express yourself with cool emoticons http://messenger.msn.co.uk
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] need help with foreach()

2003-03-09 Thread David Rice
Hey thank's for the ideas but  neither of them work, doh...

Okay fredrik I know your idea won't work cos list only works with numericaly 
indexed arrays, both the arrays that i am using are indexed by date.
(it produces a parse error when run)
=
while(list($d, $t) = each($tips)){
  $res = $t / $staff[$d];
  // Do what you need with $res ...
}
=

Janet your idea i would have thought would work but i can't get it to, 
for some reason

whenever I run the script it just gives me...
Warning:  Invalid argument supplied for foreach() in 
/home/filterseveuk/public_html/project/tips.php on line 56
Not sure as to what it is talking abotu here as far as I know, this should 
work.

=
foreach($tips as $key = $value){
    $pointvalue[$key] = $value / $staff[$key] ;

 }

==

Does anyone else have a solution!?
Cheers,
Dave


In a message dated 3/9/2003 2:07:26 PM Pacific Standard Time, 
[EMAIL PROTECTED] writes:



Okay, i have two arrays, $tips and $staff

$tips has a key date (which is the date of the first day of the week, the
second result in the array has the key of the second day of the week etc...
) and the value is a floating point decimal.
$staff also has a key date and the value is an integer, the number of
staff working in one day.
To find out the ammount of tips every staff member is to get we have to
divide the value of $tips by the value of $staff (when the dates are the
same)
what i was trying  to get this to work is below,

any help would be great,
cheers
dave
=
foreach($tips as $key = $value){

    $pointvalue[$key] = $value / current($staff) ;

    next($staff);
    }


_
It's fast, it's easy and it's free. Get MSN Messenger today! 
http://messenger.msn.co.uk

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


Re: [PHP-DB] need help with foreach()

2003-03-09 Thread Fredrik de Vibe
[EMAIL PROTECTED] (David Rice) writes:
 Hey thank's for the ideas but  neither of them work, doh...
 Okay fredrik I know your idea won't work cos list only works with
 numericaly indexed arrays, both the arrays that i am using are indexed
 by date.

You really had me wondering there for a moment. I've done this dozens
of times and list() does work with other than numerical values.

 (it produces a parse error when run)

Ok, I hadn't tested the code. For some reason you have to group $t /
$staff[$d] in parantheses, why I really don't know, it shouldn't be
necessary.

 =
 while(list($d, $t) = each($tips)){
   $res = ($t / $staff[$d]);
  ^   ^
   // Do what you need with $res ...
 }
 =

The code below is tested and works.
---
$tips = array(foo = bar,
  bar = foo);

$staff = array(foo = foobar,
   bar = barfoo);

while(list($d, $t) = each($tips)){
  printf(%s - %s - %sbr\n, $d, $t, $staff[$d]);
}


-- 
--Fredrik
New systems generate new problems.

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



Re: [PHP-DB] need help with foreach()

2003-03-09 Thread Jason Wong
On Monday 10 March 2003 08:10, David Rice wrote:
 Hey thank's for the ideas but  neither of them work, doh...

 Okay fredrik I know your idea won't work cos list only works with
 numericaly indexed arrays, both the arrays that i am using are indexed by
 date. (it produces a parse error when run)

Parse error simply means the code has a syntax error. Not necessarily that the 
idea doesn't work.

 Janet your idea i would have thought would work but i can't get it to,
 for some reason

 whenever I run the script it just gives me...
 Warning:  Invalid argument supplied for foreach() in
 /home/filterseveuk/public_html/project/tips.php on line 56
 Not sure as to what it is talking abotu here as far as I know, this should
 work.

 =
 foreach($tips as $key = $value){

 $pointvalue[$key] = $value / $staff[$key] ;

  }

What does print_r($tips) give you? While you're at it do a var_dump($tips) as 
well.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
Too cool to calypso,
Too tough to tango,
Too weird to watusi
-- The Only Ones
*/


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