Re: [PHP-DB] Array Pointer

2003-06-05 Thread Chris Mach
My database is set up in this way:

fan_roster: has player id (play_id) , week, and stats on that player for
that week. So there are 20 records for each player, because there are 20
weeks.

So what I need to do is add up all the players weekly totals. so pass_yrd1
for week1 + pass_yrd1 for week2 etc.

Then I need to put the season total for that players passing yards into my
roster table under pass_yrd. The roster table only as 1 record per player
and has season stats instead of weekly stats.

So when my loop goes through and doesn't match $i with ros_id. I need to
advance $i one but ros_id needs to stay the same until there is a match.

As you can see form this url:
http://55yardline.cflmain.com/55main/2003/fantasy/tests/update.php
it's kind of working, except where there are holes in the roster table..
for example, there is no ros_id equal to 12 so it should echo 12 no player
but it seems to skip.

Hope that makes sense.


Mike Ford [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  -Original Message-
  From: Ian Fingold [mailto:[EMAIL PROTECTED]
  Sent: 03 June 2003 16:58
 
  Ok I'm trying to write this function to up date some fields
  in my database
  so i'm grabbing some info from a query and throwing it into
  an array (with
  mysql_fetch_array).
 
  one of the values i'm puting into that array is the table id. I'm then
  comparing the table id with the value of $i in my loop. Now
  my problem is
  when I loop through and the table id is not equal to $i I
  need to add 1 to
  $i but I need to move the array pointer back one.
 
  In the code below I used prev() but i'm getting warnings
  about the Passed
  variable is not an array.
  http://55yardline.cflmain.com/55main/2003/fantasy/tests/update.php
 
  I'm thinking that prev() must not view an array fetch from a
  database the
  same or something. But what else can I use besides prev() to
  rewind the
  pointer by 1?
 
  Thanks,
 
 
  ?php
 
  include function.php;
  connect1();
 
  //query roster database and put results into an array.
  $num1 = mysql_query(SELECT * FROM roster);
  $num2 = mysql_fetch_array($num1);
  //set i to zero
  $i = 0;
 
  //start loop to determine if $i matches the current roster id
  do {
$i = $i + 1;
if ($num2[ros_id] == $i) {
  //if a match is found, query the fan_roster database
  where the play_id =
  $i
  //and put the results into a array
  $upd = mysql_query(SELECT * FROM fan_roster WHERE play_id='$i');
  $updr = mysql_fetch_array($upd);
  //loop through the passing field and add them up
  do {
  $passing = $passing + $updr[pass_yrd1];
  } while($updr = mysql_fetch_array($upd));
 
  //Print feedback
  echo Player:$i total Passing: $passing $updr[play_id]br;
 
  //update the roster table with the total $passing where ros_id=$i
  $upd1 = mysql_query(UPDATE roster SET pass_yrd='$passing' WHERE
  ros_id='$i');
  //reset passing for next loop
  $passing = 0;
} else {
  //if there isn't a match, add 1 to $i
  $i = $i + 1;
 
  //print feedback
  echo $i no playerbr;
 
  //put the array pointer back one for next loop
  $num2 = prev($num2[ros_id];

 (1) prev() takes an array as its argument, not an individual element, so
prev($num2) would be syntactically correct (but I doubt it's what you really
mean).
 (2) anyway, this whole statement is pointless as you immediately do:

}
  } while($num2 = mysql_fetch_array($num1));

 Which promptly overwrites the value of $num2 you just put there!

 What are you *really* trying to do?
  ?
 
 
 
  --
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 



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



RE: [PHP-DB] Array Pointer

2003-06-04 Thread Ford, Mike [LSS]
 -Original Message-
 From: Ian Fingold [mailto:[EMAIL PROTECTED]
 Sent: 03 June 2003 16:58
 
 Ok I'm trying to write this function to up date some fields 
 in my database
 so i'm grabbing some info from a query and throwing it into 
 an array (with
 mysql_fetch_array).
 
 one of the values i'm puting into that array is the table id. I'm then
 comparing the table id with the value of $i in my loop. Now 
 my problem is
 when I loop through and the table id is not equal to $i I 
 need to add 1 to
 $i but I need to move the array pointer back one.
 
 In the code below I used prev() but i'm getting warnings 
 about the Passed
 variable is not an array.
 http://55yardline.cflmain.com/55main/2003/fantasy/tests/update.php
 
 I'm thinking that prev() must not view an array fetch from a 
 database the
 same or something. But what else can I use besides prev() to 
 rewind the
 pointer by 1?
 
 Thanks,
 
 
 ?php
 
 include function.php;
 connect1();
 
 //query roster database and put results into an array.
 $num1 = mysql_query(SELECT * FROM roster);
 $num2 = mysql_fetch_array($num1);
 //set i to zero
 $i = 0;
 
 //start loop to determine if $i matches the current roster id
 do {
   $i = $i + 1;
   if ($num2[ros_id] == $i) {
 //if a match is found, query the fan_roster database 
 where the play_id =
 $i
 //and put the results into a array
 $upd = mysql_query(SELECT * FROM fan_roster WHERE play_id='$i');
 $updr = mysql_fetch_array($upd);
 //loop through the passing field and add them up
 do {
 $passing = $passing + $updr[pass_yrd1];
 } while($updr = mysql_fetch_array($upd));
 
 //Print feedback
 echo Player:$i total Passing: $passing $updr[play_id]br;
 
 //update the roster table with the total $passing where ros_id=$i
 $upd1 = mysql_query(UPDATE roster SET pass_yrd='$passing' WHERE
 ros_id='$i');
 //reset passing for next loop
 $passing = 0;
   } else {
 //if there isn't a match, add 1 to $i
 $i = $i + 1;
 
 //print feedback
 echo $i no playerbr;
 
 //put the array pointer back one for next loop
 $num2 = prev($num2[ros_id];

(1) prev() takes an array as its argument, not an individual element, so prev($num2) 
would be syntactically correct (but I doubt it's what you really mean).
(2) anyway, this whole statement is pointless as you immediately do:

   }
 } while($num2 = mysql_fetch_array($num1));

Which promptly overwrites the value of $num2 you just put there!

What are you *really* trying to do?
 ?
 
 
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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