Notice: Undefined variable: ctr in C:\xampp\htdocs\photo\pho

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Notice: Undefined variable: ctr in C:\xampp\htdocs\photo\pho

Post 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
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by anantha »

it should be $ctr
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post 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.
Last edited by McInfo on Thu Feb 24, 2011 5:18 pm, edited 1 time in total.
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by seuntech »

if i assigned it a value like $ctr = "good";
then $ctr++;

i still get the same error
Last edited by seuntech on Thu Feb 24, 2011 5:20 pm, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by McInfo »

Post the code.
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by seuntech »

$x = $start+$ctr+++1;

the value of $start changes
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by McInfo »

Post all of the code related to those three variables, please.
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post 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
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by seuntech »

if it were you how would you get a number like 1 2 3 4 5 6 78 in a while loop
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by danwguy »

Code: Select all

for($i=0; $i<8; $i++)
something like that.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post 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
}
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post 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
seuntech
Forum Newbie
Posts: 13
Joined: Thu Feb 24, 2011 4:54 pm

Re: Notice: Undefined variable: ctr in C:\xampp\htdocs\photo

Post by seuntech »

please
Post Reply