bashaclick Posted March 31, 2011 Share Posted March 31, 2011 HI All, I would like create query when I add some one is look what the last number in field and add one ? example : you can see the img in attach IDT is primary key + auto increment Customer_id is number field customer _name is name how can create this login IDT Customer_ID Customer_name 112 5 bbbb 113 6 ccccc 114 7 eeeee Also I need the inster function and is look the last field in customer_ID and Increase one ( +1) Any help PLZ/ THanks [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/232241-how-can-create-insert-function/ Share on other sites More sharing options...
3raser Posted March 31, 2011 Share Posted March 31, 2011 HI All, I would like create query when I add some one is look what the last number in field and add one ? example : you can see the img in attach IDT is primary key + auto increment Customer_id is number field customer _name is name how can create this login IDT Customer_ID Customer_name 112 5 bbbb 113 6 ccccc 114 7 eeeee Also I need the inster function and is look the last field in customer_ID and Increase one ( +1) Any help please/ THanks Probably a better way of doing this then what I'm showing you.... Well you can do something like this: $extract = mysql_query("SELECT customer_id FROM tablenamehere ORDER BY customer_id DESC"); $extract_e = mysql_fetch_assoc($extract); mysql_insert("INSERT INTO tablenamehere VALUES (null, '". $extract_e['customer_id'] + 1 ."', '$customer_name')"); Link to comment https://forums.phpfreaks.com/topic/232241-how-can-create-insert-function/#findComment-1194751 Share on other sites More sharing options...
bashaclick Posted March 31, 2011 Author Share Posted March 31, 2011 Thank you this my simple code mysql_connect("localhost", "root", "asdasd") or die("Could not connect: " . mysql_error()); mysql_select_db("attawy"); $extract = mysql_query("SELECT customer_id FROM orders ORDER BY customer_id DESC"); $extract_e = mysql_fetch_assoc($extract); mysql_query("INSERT INTO orders (customers_id,customers_name) values ('". $extract_e['customer_id'] + 1 ."','kossu')"); and show me error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource !!! Any Idea Thank Link to comment https://forums.phpfreaks.com/topic/232241-how-can-create-insert-function/#findComment-1194754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.