PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old May 15th, 2008, 09:28 PM
wilorichie wilorichie is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Brisbane
Posts: 129 wilorichie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 30 m 4 sec
Reputation Power: 2
logic - Item ID numbers

Hey guys...

I insert a product into the database... now I want to get the ID of that product just inserted.

The way I am doing it now works fine, but I feel its a bit dodge... It just might have a glitch if there are heaps of people adding a product at once...

Code:
// insert the item into the database //
$gitem_insert = gitem_insert($cat, $subcat, $title, $price, $description, $state, $suburb, $phone, $email, $cnote);
$query = mysql_query($gitem_insert);

// crunch time //
if($query){

	// gather the ID of the new added element //
	$last_gitem = last_gitem();
	$queryn = mysql_query($last_gitem);
	
	while($row = mysql_fetch_assoc($queryn)){
		$id = $row['product_id'];
	}
	
	// FORM: image //
	if(($_FILES['image']['type'] == "image/pjpeg") || ($_FILES['image']['type'] == "image/jpeg") || ($_FILES['image']['type'] == "image/gif")){							
		// Gather details INCASE we need to resize //
		$filelol 		= $_FILES['image']['tmp_name'];
		$source			= imagecreatefromjpeg($filelol);
		$destination	= "images/gitems/$id-m-gitem.jpg";
		$quality		= 70; // image quality //
		$limits 		= 300; // max width //							
		// call the function to resize the image //
		image_resize($filelol, $source, $destination, $limits, $quality);							
	}

}


As you can see, I use the product ID in the image name... But... It's done dodge... what if 2 people add products at the exact same time...

Any tips, suggestions or someone possible tell me the CORRECT way to do this.. haha...

Thanks in advance guys!

Richie
__________________
- Richie

Reply With Quote
  #2  
Old May 15th, 2008, 10:36 PM
cwf's Avatar
cwf cwf is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 353 cwf User rank is Private First Class (20 - 50 Reputation Level)cwf User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 50 m 34 sec
Reputation Power: 2
Take a look at mysql_insert_id()

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > logic - Item ID numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway