Gayner Posted September 25, 2009 Share Posted September 25, 2009 I want to make it so each time a user uploads a image, it gives it a unique user_id Is there php function to generate a unique id starting from number 500? and goes each time that query is ran, 501,502,503, etc.. each time the query is ran thx Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/ Share on other sites More sharing options...
Alex Posted September 25, 2009 Share Posted September 25, 2009 You should use an AUTO_INCREMENT field Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925095 Share on other sites More sharing options...
Gayner Posted September 25, 2009 Author Share Posted September 25, 2009 You should use an AUTO_INCREMENT field Wont work as there's alrdy one in user_id i made new field cimage, people upload image, i need id for each image too ?? Unless i can have 2 auto increment fieldS? Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925108 Share on other sites More sharing options...
Philip Posted September 26, 2009 Share Posted September 26, 2009 Can you post your table schema? Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925116 Share on other sites More sharing options...
Gayner Posted September 26, 2009 Author Share Posted September 26, 2009 Can you post your table schema? include(ROOT_PATH . 'includes/init.php'); global $DB, $settings, $user_info, $forum_info_arr, $language; if ($user_arr['points'] >= 100) $lol = "I have more then 100 FC!"; else $lol = " I haveless then 100FC!"; echo $lol; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("avatars/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $timestamp = date("D, M j Y, h:ia"); mysql_query("INSERT INTO `la_items_purchased` (`item_id`,`user_id` ,`points_spent` ,`purchase_date` ,`cimage`) VALUES ( '". mysql_real_escape_string($_FILES["file"]["name"]) ."', '". mysql_real_escape_string($user_info[user_id]) ."', '". mysql_real_escape_string('100') ."', '". mysql_real_escape_string($timestamp) ."', '". mysql_real_escape_string($_FILES["file"]["name"]) ."'); "); move_uploaded_file($_FILES["file"]["tmp_name"], "avatars/" . $_FILES["file"]["name"]); echo "Stored in: " . "avatars/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925118 Share on other sites More sharing options...
Philip Posted September 26, 2009 Share Posted September 26, 2009 user_id doesn't look like its an auto incremented field to me... Use an auto incremented key on item_id, and when inserting, use mysql_insert_id() Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925167 Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 Sorry but it looks like you got a real good understanding of database normalization, why are you generating the item id like that... Was you suppose to add a auto increment_id at the beginning of that database? Just make no seance with that grate database structure. actually thinking about it, if you make the field item_id UNIQUE, in the database, you could use mysql_insert_id() function, but i would take the below advise,might go wrong my idea mate. sorry to go on but dam dam dam normalization for mysql is a hard subject on it own, don't get why your item_id looks this way please tell me lol. Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925168 Share on other sites More sharing options...
Gayner Posted September 26, 2009 Author Share Posted September 26, 2009 Sorry but it looks like you got a real good understanding of database normalization, why are you generating the item id like that... Was you suppose to add a auto increment_id at the beginning of that database? Just make no seance with that grate database structure. actually thinking about it, if you make the field item_id UNIQUE, in the database, you could use mysql_insert_id() function, but i would take the below advise,might go wrong my idea mate. sorry to go on but dam dam dam normalization for mysql is a hard subject on it own, don't get why your item_id looks this way please tell me lol. item_id joins with user_id which is joined table from forums. Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925173 Share on other sites More sharing options...
Philip Posted September 26, 2009 Share Posted September 26, 2009 But user_id isn't an auto_incre'd field in this table. Thus, you can have one - your item id. Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925175 Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 so you forgot to add a auto increment to the database structure interesting. KICK UR SELF LOL 1 min let think, if the id of the forum is item_id now, that means in theory that there be no duplicates, so u can just use insert_id() innit? Quote Link to comment https://forums.phpfreaks.com/topic/175560-generate-random-number-each-query/#findComment-925176 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.