Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-07-2006, 11:36 AM   #1 (permalink)
tomycon
Registered User
 
Join Date: Jul 2002
Location: Massachusetts
Posts: 6
tomycon is on a distinguished road
using empty row to trigger if

Hello,

I'm trying to get an empty result from a postgresql query to trigger an "if" loop. More specific, I query the db for data on a specific item that if fact does not exist in the db, so "0 rows" are returned. What is the value to pass to php to start the if - else loop?

Here is a sample of the code:
PHP Code:
<?PHP

     $dbconnO 
pg_Connect ("dbname=contact_data user=httpd password=httpd");

    if (!
$dbconnO) {
             echo 
"</table>A dbconnO error occurred.\n";
             exit;
             }

    
$rsltTEST pg_Exec($dbconnO,
    
"SELECT job_no
    FROM proj_contact
    WHERE proj_contact.job_no = '$cntct_jno';"
);


    if (
$rsltTEST == 0) {
                    echo 
"No job number exists.\n";
                    exit;
                    } else {
I'm sure there is a very simple answer to this but I haven't come across it yet! Thanks for your time and attention!
tomycon is offline   Reply With Quote
Old 04-07-2006, 11:54 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
hmm.. could something like:
PHP Code:
if(!isset($rsltTEST)) || $rsltTEST === ""
do it ??
I've never interacted with postgresql from PHP, so I'm not sure how the $rsltTEST will be formed, why not try and print it to the screen, so you'll know what to match for ?
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-07-2006, 12:33 PM   #3 (permalink)
tomycon
Registered User
 
Join Date: Jul 2002
Location: Massachusetts
Posts: 6
tomycon is on a distinguished road
Thanks for the quick reply!

Printing to the page using:
PHP Code:
echo  $rsltTEST
shows up as "Resource id #3" ?!?

Your suggestion results in "Parse error: parse error, unexpected T_BOOLEAN_OR in ..."

I'm not sure what any of that means!
tomycon is offline   Reply With Quote
Old 04-07-2006, 12:56 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
Then how about this:
PHP Code:
<?PHP 

     $dbconnO 
pg_Connect ("dbname=contact_data user=httpd password=httpd"); 

    if (!
$dbconnO) { 
             echo 
"</table>A dbconnO error occurred.\n"
             exit; 
             } 

    
$rsltTEST pg_Exec($dbconnO
    
"SELECT job_no 
    FROM proj_contact 
    WHERE proj_contact.job_no = '$cntct_jno';"
); 


    if (! (
$row pg_fetch_row($rsltTEST))) { 
                    echo 
"No job number exists.\n"
                    exit; 
                    } else { 
                     echo 
"Job exists " $row['some_label'];
                     while(
$row pg_fetch_row($rsltTEST))
                           echo 
"<br>" $row['some_label'];
         }
Or this:
PHP Code:
$rsltTEST pg_Exec($dbconnO
    
"SELECT job_no 
    FROM proj_contact 
    WHERE proj_contact.job_no = '$cntct_jno';"
); 


    if (! 
pg_num_rows($rsltTEST)) { 
            
// nothing there 
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-07-2006, 01:12 PM   #5 (permalink)
tomycon
Registered User
 
Join Date: Jul 2002
Location: Massachusetts
Posts: 6
tomycon is on a distinguished road
Thumbs up

That works!
Your
PHP Code:
if (! ($row pg_fetch_row($result))) 
did the trick! Just had to change it to "$rsltTEST".
Thanks for your perseverance and brainstorming!
tomycon is offline   Reply With Quote
Old 04-07-2006, 04:05 PM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
For persistance I would suggest to use my last example where you query for how many rows the result holds, there you will not try to fetch any befor they need to be used.
Thus keeping every bit of info stored in your $rsltTEST untill needed, no matter if the result is NILL or more.

But what the hell, I'm drunk now, and it works
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight a DataGrid Row and Stay there - rikb53 MS Technologies ( ASP, VB, C#, .NET ) 0 03-09-2006 11:26 AM
change the empty function from the old format to the new format powah All Other Coding Languages 1 07-10-2005 01:23 PM
Row Decrement Phantek Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 6 05-20-2005 10:59 AM
empty pointers are not empty using 'new' operator DJMaze Platform/API C++ 3 04-16-2005 12:11 AM
DataReader empty watherton MS Technologies ( ASP, VB, C#, .NET ) 3 06-15-2004 11:58 AM


All times are GMT -8. The time now is 05:36 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting