Welcome Guest, Not a member yet? Register   Sign In
auto increment field makes problem in my project
#1

I am using one auto increment key for every applicant. when i am deleting all files 

when insert into my table the values are not resetted.

Code:
    $query = $this->db-> query ("SELECT max(appno) as max_id FROM appno");
           $row = $query-> row_array ();
           $max_id = $row ['max_id'];
           $max_id1 = (int) ($max_id);
           $appno = $max_id1+1;
  
i run the query in mysql prompt it shows correct value but the values inserted as last value +1 
any suggestion
Reply
#2

It is not clear what you are doing after you calculate $appno.
How are you using $appno?
Reply
#3

It is not going to give you the result the right way unless you write it back
to the database and re-read it.

PHP Code:
$data['appno'] = ++$max_id1;

$this->db->update('appno'$data); 

I also hope that your table name is not appno and you have a field appno.

Because the table name needs to be unique.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(10-06-2018, 08:35 AM)InsiteFX Wrote: It is not going to give you the result the right way unless you write it back
to the database and re-read it.

PHP Code:
$data['appno'] = ++$max_id1;

$this->db->update('appno'$data); 

I also hope that your table name is not appno and you have a field appno.

Because the table name needs to be unique.

my table name is appno and field name also appno. is it makes problem?. I am inserting this appno into the table when submit button. 
not an inserting problem. but i am starting this appno : 80001 each user click this button increased perfectly . i clear the table except 80000. after i  click the button the value inserted as that max value+1 . but i want the field to be 80001. need suggestion
Reply
#5

(This post was last modified: 10-07-2018, 05:47 PM by InsiteFX.)

They should be different you never add a database field with the name of the table.

If the field is an auto increment field you need to delete the table and recreate it.

In your case I would not use an auto increment field create a field an give it a
unique key.

You will need to handle the increment yourself self.

create an auto increment using id and then say for the unique key app_id.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

It really depends what you are doing.

Are you creating new rows every time someone clicks on the button or are you counting how many clicks people have made, for that button, and update existing row?
Reply
#7

(10-08-2018, 01:41 AM)Pertti Wrote: It really depends what you are doing.

Are you creating new rows every time someone clicks on the button or are you counting how many clicks people have made, for that button, and update existing row?

each user clicks this button it creates maxid+1 value . this value inserted into the table. 
for example if 10 user clicks this button the values are 80001 to 80010 stored in table.
now i clear all table fields showing fresh. the starting value is only available my table (80000)
. In that position i click the button the value 80011 only be inserted not 80001. 
this is my problem. the values are not resetting .
In my table  values are
80000
80011
Reply
#8

Selecting, then adding to figure on PHP side, then inserting back to DB sounds like very unreliable way to do this.

If at all possible, use auto increment and build your system so going from 80000 to 80011 doesn't matter. This way you don't have to do extra work, but also are guaranteed to get unique IDs.

If you are 100% certain you do not have 80010 somewhere hidden in your DB, it suggests to me that either DB or CI is doing caching, and deleting rows does not flush that cache, so effectively you get most recent returned result, which was 80010.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB