|
|
Subject:
PHP mySQL case then select inser question
Category: Computers > Programming Asked by: piotrsienkiewicz-ga List Price: $10.00 |
Posted:
15 Jun 2005 08:30 PDT
Expires: 18 May 2006 07:30 PDT Question ID: 533532 |
Here is my current PHP/MySQL code: $pub_query = $this->query("SELECT id FROM $db_table WHERE name = '$value'"); if ((mysql_num_rows($pub_query) == 0)) { //echo "ZERO"; $this->query("INSERT INTO $db_table (name) VALUES ('$value')"); return mysql_insert_id(); } else { //echo "NOT ZERO"; $pub_results = mysql_fetch_array($pub_query); return $pub_results['id']; } This means that 2 queries are performed.. instead of 1. I'm currently working with about 400,000 rows of data, and need to cut back where ever I can. I know there is a CASE statement in MySQL that may be able to do this. CASE WHEN search_condition THEN statement_list [WHEN search_condition THEN statement_list] [ELSE statement_list] END CASE If not maybe an IF statement that can get the same job done. |
|
There is no answer at this time. |
|
Subject:
Re: PHP mySQL case then select inser question
From: soneji-ga on 16 Jun 2005 13:02 PDT |
What you are trying to achieve is possible in mysql 4.0. You can find some sample code on creating stored procs in MySQL on this link. http://forums.mysql.com/read.php?98,19146,page=2 |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |