Hi, i made this, i think this is working.. but i need the a final answer by an expert! Right now the script is working 100% with the multi-uploader. It seems to be working correct but im not sure when my databse will have 250 000 rows if its still gonna work fine. The goal is to add a unique $mid into the databse for the uploaded file. If the row exist, continue to make a random number with max 5 numbers until the $mid is unique in the database The code is below, i pasted only the necessary code. [...] move_uploaded_file($tempFile,$targetFile); //créé un mid de 5 chiffre unique do{ //faire ceci en loop $mid = rand(11111, 99999); $result_mid = mysql_query("SELECT mid FROM wallpapers WHERE mid = '".$mid."'"); $numrows = mysql_num_rows($result_mid); if ($numrows == 0){ $uid_string = $sql_categorie.$sql_file; $uid = hash(md5, $uid_string); // chaque marque a son md5. mysql_query ( "INSERT INTO wallpapers VALUES ('', '$mid', '$uid', 'oui', '". $mature ."', '". $sql_categorie ."', '" .$sql_path. "', '" .$sql_file. "', '0');") or die (mysql_error()); } } while ($numrows); //exécute le do en loop avec une condition PHP: Thanks very much!
Hi! First Of All... Don't Use Single Quotes With Numeric Value In Your Queries. U Set Numeric Value In $mid; So Don't With Single Quotes With $mid. $result_mid = mysql_query("SELECT mid FROM wallpapers WHERE mid = ".$mid); Do Same Action With This All Queries. Now! Wait For An Expert To Solve Your Problem
Yeah thanks but i need only digits, as exemple, look here and click on Web to Mobile orange button at your right (under the Preview). The mid code is for the WAP id to get the wallpaper on your mobile. I want it 5 digits. Plus your code verify nothing.
Let MySQL do the work for you. Make mid your primary key as auto increment with UNSIGNED ZEROFILL attribute of type int(5). This will give you numbers of 00000 until 99999. The problem being is after 99999 you either have to increase the digit count or delete ones that are used (if that is how it works). move_uploaded_file($tempFile,$targetFile); $uid_string = $sql_categorie.$sql_file; $uid = hash(md5, $uid_string); // chaque marque a son md5. // Assuming mid if the primary key, auto increment mysql_query ( "INSERT INTO wallpapers VALUES ( '$uid', 'oui', '". $mature ."', '". $sql_categorie ."', '" .$sql_path. "', '" .$sql_file. "', '0');") or die (mysql_error()); // Get the unique mid generated by MySQL $mid = mysql_insert_id(); PHP:
Ok great but normaly.. i already have ID auto increment in my table. this is my default. I still set mid as primary key ? JHere is a sc of my table structure structure Normal
You can not have two auto increments or primaries at the same time. You have to remove the id field, however, you will have to update your coding to reflect it so and use the mid as the ID instead.
Ok great and thanks imma use this right now. I already think about that method but for my personal knowledge I wish to know how to solve my problem