Array Pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 player<br>";

    //put the array pointer back one for next loop
    $num2 = prev($num2["ros_id"];
  }
} while($num2 = mysql_fetch_array($num1));
?>



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux