Re: True/false value of SELECT statement.

From: Date: Tue, 01 Aug 2000 11:43:40 +0000
Subject: Re: True/false value of SELECT statement.
Groups: php.db 
Request: Send a blank email to php-db+get-1666@lists.php.net to get a copy of this message
Once you have a criteria to reconize one record from the others you have a field or a group of fields of this table that make the record unique. If you can, you have a good where clause to look for before insert the new record. "SELECT * FROM table WHERE field = $input1 [and field2 = $input2 [and ...]] " . In this case if you get a valid result you have a similar record on your database and you can use the structure you put in your previous message. Another way is to make a unique index on this(s) field(s) and try the INSERT query, if the record allready exists it will return an insert error,1062 in MySQL (I don't know wich one in PostgreSQL ), you can catch and handle like: if (!$resultSet) {// Insert failed <put a message or procedure> } else {// On Insert success <other procedures> } I hope this helps. Jayme. -----Mensagem original----- De: Tim <tj198@soton.ac.uk> Para: php-db@lists.php.net <php-db@lists.php.net> Data: Segunda-feira, 31 de Julho de 2000 18:17 Assunto: [PHP-DB] True/false value of SELECT statement. >I'm using a SELECT statement in my PostgreSQL db to test if a record has >already been added. If it hasn't, then obviously there is no result. How do >I set up an if/else structure to handle this? > >I've been trying: > >if (!$resultSet) { > > add the record > >} else { > > don't add it (but i need this else block because i'm using it to add >something to another part of the db) > >} > >... but this doesn't seem to work. > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net >For additional commands, e-mail: php-db-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#1666) next »