mehdi_php Posted October 14, 2008 Share Posted October 14, 2008 hi , i have profile column in mysql . +-----------------+ | xprofile_id | 1 | 2 | 3 +------------------+ if i delete 2 and 3 sql = insert into xxprofile (col1 , col2 ) values (xx1 , xx2 ) ; +-----------------+ | xprofile_id | 1 | 4 | 5 +------------------+ how can i perevent this ? i want to insert with correct id so i can use sql = select max(xprofileid) from xxprofile ; then increment by one to run other operations Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/ Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 What do you mean with "correct ID"? It's standard practice not to reuse IDs because they're supposed to be unique. Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664782 Share on other sites More sharing options...
mehdi_php Posted October 14, 2008 Author Share Posted October 14, 2008 if i delete 2,3 they are no longer exist so they are unique . right ? i want to insert with 2,3 if the are deleted already Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664788 Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 Well, imagine that you had view_article.php?id=153 People might link to that. Now imagine that I deleted article 153 and later added a new one. Now you would have inconsistency because 153 is now something else. Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664793 Share on other sites More sharing options...
mehdi_php Posted October 14, 2008 Author Share Posted October 14, 2008 yes , you right . but take a look at this code please . <?php //get last profile id $last_id = $db->get_var("select max(xprofileid) from xxprofile ") ; //upload the file if($file->isValid()){ $sum = $count+1 ; //open images directory $file->setName(($last_id+1).'.jpg'); $fp = PROFILE.$id; $moved = $file->moveTo($fp); if(!PEAR::isError($moved)){ list($w , $h ) = getimagesize($fp.'/'.($last_id + 1 ) .'.jpg' ) ; if($w > 800 && $h > 600 ){ $err_upload[] = 'invalid dimensions ' ; unlink($fp.'/'.$last_id.'.jpg'); }else{ echo '<div id="notic">upload was successfull </div>'; header("Location :?section=profile&id=$id"); } }else{ echo 'error on file upload '; } } ?> i have to check image dim befor any insert into my database so i can't use $db->insert_id so i have to increament by one the max last id . what can i do ? Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664799 Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 Do SHOW TABLE STATUS LIKE 'xxprofile'; Then use the Auto_increment row. Please note that the auto_increment value is +1 of the last inserted ID. Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664805 Share on other sites More sharing options...
mehdi_php Posted October 14, 2008 Author Share Posted October 14, 2008 very good Help Tank you . works nice . i have another problem . i this forum when a post submitted in each forum page shows how many time this post has been seen by users but if i once see it , it's increment by one but if i agin see it , it's not increment how it works ? i do it by sessions but every time another user see it the session is overwrite and previous user can increment the post views number . Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664810 Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 I'd guess it uses the forums read/unread system to determine whether it should be updated or not. Basically, if this was marked as unread then you update the view count. Otherwise you don't. Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664811 Share on other sites More sharing options...
mehdi_php Posted October 14, 2008 Author Share Posted October 14, 2008 ok . but i think it's possible for site users what if we want to implement for guess users ? Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664817 Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 It's going to be a bit more difficult with guests. I guess you can store a cookie on the guests' computer storing what they have and haven't read. You can then check against that. It's not completely accurate though. Quote Link to comment https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/#findComment-664819 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.