auto increment question

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
kingkol
Forum Newbie
Posts: 4
Joined: Mon Nov 08, 2010 12:24 am

auto increment question

Post by kingkol »

hi

I am new to php.I want to know is there a way to controlling the auto-increment process.
I am making a guest book project.I want comments to store in mysql database table and appear on alternate background,like--dark,white,dark.my 'id' field is primary and auto-increment.and making alternate background by--

Code: Select all

if($var1%2)
{
div class="grey";
.....
....
}
else
{
div class="white"
.....
.....
}
my problem is if i delete a comment from table then this alternative background pattern does not work.say...if I delete 4th comment whose id=4 then new comment adds with id=5,not 4.I want that to be 4th and so on. In plain---i want if a comment is deleted from table then the following comment will jump up to 1 position.how to do that????
please help

thanks in advance
mehran
Forum Newbie
Posts: 17
Joined: Fri Jan 21, 2011 1:31 am

Re: auto increment question

Post by mehran »

if you get the value from the database insisted of the id you will not get this problem
kingkol
Forum Newbie
Posts: 4
Joined: Mon Nov 08, 2010 12:24 am

Re: auto increment question

Post by kingkol »

thanks for quick reply.
Sorry i dint get you.could you please explain.I am a newbie.
mehran
Forum Newbie
Posts: 17
Joined: Fri Jan 21, 2011 1:31 am

Re: auto increment question

Post by mehran »

currently you are using the id approach to get data from database
change your approach,get data from database through another column like name,
mehran
Forum Newbie
Posts: 17
Joined: Fri Jan 21, 2011 1:31 am

Re: auto increment question

Post by mehran »

sorry i cnnt understand your question,
now i understand what is the problem,
if(){
}else{
}
must be in a loop
plz declare a vaiable outside of the loop then pass that variable to the to the condition statment
like $check=1;
while(){
if($check%2){

<div></div>
}else{
<div></div>
}
i hope now your problem will be solved
Post Reply