RE: adding a new record

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A non-zero result only means the query executed ok.  It doesn't mean any
rows matched the select and were returned.  Either check the number of
rows selected, or try to retrived one of the rows:

$SQLresult = Query the DB to see if record(s) exists
If(0 == *_num_rows($SQLresult)){
   insert new data;
 }else{
   echo "Data already exists in table.";
}

> -----Original Message-----
> From: Becoming Digital [mailto:info@becomingdigital.com] 
> Sent: Tuesday, May 06, 2003 2:07 PM
> To: php-db@lists.php.net
> Subject: Re:  adding a new record
> 
> 
> Make sure you use if(), not If().
> 
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
> 
> 
> ----- Original Message ----- 
> From: "Gavin Amm" <Gavin@ksg.com.au>
> To: <php-db@lists.php.net>
> Sent: Monday, 05 May, 2003 22:05
> Subject: RE:  adding a new record
> 
> 
> Sorry,
> Outlook XP reformats line breaks - very anoying... trying again:
> 
> $SQLresult = Query the DB to see if record(s) exists
> If(!$SQLresult){
>   insert new data;
> }else{
>   echo "Data already exists in table.";
> }
> 
> 
> Gav
> 
> 
> 
> -----Original Message-----
> From: Gavin Amm 
> Sent: Tuesday, 6 May 2003 12:02 PM
> To: php-db@lists.php.net
> Subject: RE:  adding a new record
> 
> 
> Hi Jake,
> Not sure what your table structure is like...
> 
> $SQLresult = Query the DB to see if record(s) exists If(!$SQLresult){
>   insert new data;
> }else{
>   echo "Data already exists in table.";
> }
> 
> 
> Cheers,
> Gav
> 
> 
> -----Original Message-----
> From: Jake Malone [mailto:jake@therussianjudge.com] 
> Sent: Monday, 5 May 2003 4:14 PM
> To: php-db@lists.php.net
> Subject:  adding a new record
> 
> 
> is there some way to construct an INSERT query such that it only adds
> the record if certain values don't already exist in the table? (not
> unlike SELECT DISTINCT). or do i have to make a seperate SELECT
> statement to check before adding?
> 
> thanks,
> -jake
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux