Jump to content

insert correct id after delete in mysql


mehdi_php

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/128332-insert-correct-id-after-delete-in-mysql/
Share on other sites

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 ?

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 .

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.