|
 |
|
 |
04-07-2006, 11:36 AM
|
#1 (permalink)
|
|
Recruit
Join Date: Jul 2002
Location: Massachusetts
Posts: 7
|
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!
|
|
|
04-07-2006, 11:54 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
|
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 ?
|
|
|
04-07-2006, 12:33 PM
|
#3 (permalink)
|
|
Recruit
Join Date: Jul 2002
Location: Massachusetts
Posts: 7
|
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!
|
|
|
04-07-2006, 12:56 PM
|
#4 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
|
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
|
|
|
04-07-2006, 01:12 PM
|
#5 (permalink)
|
|
Recruit
Join Date: Jul 2002
Location: Massachusetts
Posts: 7
|
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!
|
|
|
04-07-2006, 04:05 PM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
|
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 
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
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 03:55 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|