Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increment a loop variable 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
$query ="UPDATE template SET Qty = " . $_SESSION['QTY'][$I] . " WHERE id = $i+1";

The above did not work. I am trying to make my loop cover 1-40 records, by selecting the ID of the record. Record ID=0 is the problem. Can someone tell me how to increment the value of $i by 1. Thanks
 
It's not very clear what you're trying to do. Can you explain a bit better?
 
Its a php thang, but something like this should do.

for ($i = 0; $i <= 39; $i++) {
$query ="UPDATE template SET Qty = " . $_SESSION['QTY'][$I] . " WHERE id = '$i'";
mysql_query($query);
}


*note, $_SESSION['QTY'][$I] <-- is that meant to be a capitol I ?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks Tony, although I have just found out I am okay. I had a loop which was selecting records by there ID being equal to $i, and I thought my problem was that it was not finding record 0. I thought I would have needed to increment the value of $i but that was not my/the problem.

$i=0;
while ($i < $num) {

Select statement in here where record ID=$1

$i++;
}

Thanks anyhow for comming back. Regards
 
Many thanks KarveR. Re for ($i = 0; $i <= 39; $i++) {
does that mean $i is moved to being 1 by the $i++ statement. In other words the first real value = 1?

Thanks, and yes it was a typo error, $I should have been $i
 
The first real value is 0, as set by $i=0, and is incremented by 1 each time until the vlue is equal to 39. this is 40 steps.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks, that now makes me think by using the ID of a record in a loop (Primary Key), I am going to miss one as the first loop of zero $i will not find a matching record ID?
And as the loop is 0 to < $num, it only would loop 0,1,2,3,4 in a 5 record database. I am mystified, as I don't seem to be losing one. I will have to do some more tests to see whats what. Thanks for now.
 
the first result from mysql_query is indexed as zero even tho the record id will be 1. its an array thing :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for solving the mystery. Have a star for putting my mind at rest. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top