RE: [PHP-DB] Array Pointer
| From: | Ford, Mike [LSS] | Date: | Wed, 04 Jun 2003 09:05:59 +0000 |
| Subject: | RE: [PHP-DB] Array Pointer | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-28293@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ian Fingold [mailto:cjmach@gto.net]
> 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 player<br>";
>
> //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
>