I look at one side to create a function in php and mysql which gives me the result of the resulting ID A record in a simple table
I found an ID -> Price table, where the ID is an AutoInternment field.
By natural or simple way I know:
$ myId = check ('paneer'); Function check ($ value) {$ sql = "SELECT id from table WHERE value = '$ value'"); $ Res = mysql_query ($ sql); If ($ res) returns mysql_result ($ res, 0); // If the record is not present then record $ sql = "insert table (value) values ('$ value')" INSERT; $ Res = mysql_query ($ sql); Return mysql_insert_id (); } OK, I think this is the classic way .. but I think a MySQL command or something that makes things easy.
I know an INSERT IGNORE but is there any way to select it, if not present and do not return the ID?
I have to do something like this:
Select the ID from the table where value = 'dummy' if not present then enter in table (value) values ('dummy')
So I will get the id in one step and MySQL will solve the problem and the code will be more efficient or quick ..
(Imagine I can do it 10000 times)
< / Div>
Use INSERT ... on duplicate key update
function check ($ value ) {$ Sql = "Entering table (value) values Duplicate key update value ($ 'value') = '$ value "; $ Res = mysql_query ($ sql); Return mysql_insert_id (); } requires mysql 5.1.12 or later
Comments
Post a Comment