0

I am currently working on a school event system where each student has their own bar-code upon registration

I have a column id in my table which is auto incremented and to make my barcode unique I generated a random integer and I want that random integer to concatenate with the auto generated id.

I would like to know how am I going to get the value of the id upon registration to concatenate the random integer to their IDs

I would like to have an idea from you guys

Thanks a lot

Here is how I insert my data from the database:

enter image description here

The thing is, I want the $temp to concatenate to the latest id that is auto incremented

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kyle Cipriano
  • 151
  • 1
  • 1
  • 9

3 Answers3

1

You can get last inserted auto increment id by using the following method of CodeIgniter

$this->db->insert_id();
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
1
<?php 
/*You should need to get last insert id after successfully registration
like this ex. */
$id = mysqli_insert_id($conn);
/*after you need to concat id with randum value like this*/
/*function for randum value*/
$randvalue = rand(11111,99999);
$barcode =$randvalue.$id;
/*now you need to update value in db*/

mysqli_query($conn,"UPDATE `table` SET `barcode`='".$barcode."' where (`id`='".$id."')");
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
0

Generally, you would use $this->db->insert_id() which will return the last inserted id from the last query performed.

If you want an accurate answer, spend the time to include some code that you already have.

digout
  • 4,041
  • 1
  • 31
  • 38