Jump to content

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 .

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.