I like to create a specific filename for a file that will be created by the input of the fields from the insert query. i like to have an unique key for that. this key consists of an user_id, a timestamp and at the end of this, it should be placed the generated insert_id from the insert query fired. it should be placed the auto_increment no. for the end of my generated variable. so the problem is, that i create a variable before the insert query fired so that this variable will be part of the insert query like:
$get_num = $db->query("SELECT COUNT (*) FROM tableA");
$num = $query->fetch_assoc();
$end = $num + 1;
$file_id = $id .".". time() .".". $end;
$insert = $db->query("INSERT INTO tableA ( file_id, a, b, c) VALUES('".$file_id."','".$a."','".$b."','".c."')");
Actually, forget what I wrote previously. You cannot count on
COUNTworking for you because what happens when a row is deleted? You will have duplicate values. The best bet for you is to first create the row, grab the insert_id, thenUPDATEthe file_id uing the function you previously described.In the end, you still have to use two queries anyway, so its not like this takes any more resources. Plus you aren’t doing a
COUNToperation anymore.In other news, please be sure to read up on SQLi, depending on where your a,b,c variable are coming from.