Page 1 of 1
Notice: Undefined variable: ctr in C:\xampp\htdocs\photo\pho
Posted: Thu Feb 24, 2011 4:59 pm
by seuntech
i am trying to do a number increment inside while loop
with ctr++ it works but i am getting this error
Notice: Undefined variable: ctr in C:\xampp\htdocs\photo\photoviewb.php on line 27
thanks
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:12 pm
by anantha
it should be $ctr
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:15 pm
by McInfo
The variable named $ctr is undefined on line 27. That means it was not assigned a value before its value was requested on line 27. Assign it a value before the loop and the error should go away.
anantha wrote:it should be $ctr
PHP wouldn't know it was a variable if it didn't have a $ prefix.
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:17 pm
by seuntech
if i assigned it a value like $ctr = "good";
then $ctr++;
i still get the same error
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:19 pm
by McInfo
Post the code.
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:22 pm
by seuntech
$x = $start+$ctr+++1;
the value of $start changes
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:24 pm
by McInfo
Post all of the code related to those three variables, please.
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:28 pm
by seuntech
it is too much to post what i am doing is try to get the position of a particular picture among other picture order by id (it works) but on the lates php only it display the error and still works
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:30 pm
by seuntech
if it were you how would you get a number like 1 2 3 4 5 6 78 in a while loop
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:37 pm
by danwguy
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:38 pm
by McInfo
Without seeing the code, all I can say about the error is that it occurs when a script requests a value from a variable that does not yet exist.
To use a while loop to increment a number,
Code: Select all
$i = 1; // Assigns an initial value
while ($i < 9) { // Continues until the value is 9 or greater
echo $i; // Uses the number
$i++; // Increments the number
}
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:45 pm
by seuntech
thanks
but u guy are not getting the point
the code must be run inside a while loop
that is what ever u give me now will be placed inside a while loop
Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo
Posted: Thu Feb 24, 2011 5:56 pm
by seuntech
please