RE: [PHP-WIN] Quick One... determining if there are no results re turned
| From: | Asendorf, John | Date: | Wed, 06 Sep 2000 12:38:08 +0000 |
| Subject: | RE: [PHP-WIN] Quick One... determining if there are no results re turned | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-2458@lists.php.net to get a copy of this message | ||
I stole Gonzalos' code:
$r=odbc_fetch_row($sql);
if ($r){
you have rows, do something
} else {
you don't have rows, do something else
}
and it seems to be working just fine. php 4.0.1 (as cgi) NT IIS4.
I use it in about 5 levels and each time it has worked correctly.
Here's the final code I ended up with:
$r = odbc_fetch_row( $easy_result );
if ($r){
if ( $error_check ){
echo "checking $street \n<br />\n";
}
get_precinct ($easy_result);
}
else { //CHECK 2
$sql_no_return1 = "SELECT rangefrom, rangeto, street, city,
precinctname, precnum
FROM Sheet1
WHERE CITY = '$city'
AND STREET LIKE('$street_no_return1')
AND RANGEFROM <= $street_number
AND RANGETO >= $street_number";
// prepare SQL statement
$no_return1 = odbc_prepare($connection,$sql_no_return1);
// execute SQL statement and get results
odbc_execute($no_return1);
$r = odbc_fetch_row( $no_return1 );
if ($r){
if ( $error_check ){
echo "checking on $street_no_return1 \n<br />\n";
}
get_precinct ($no_return1);
}
else { //CHECK 3
$sql_no_return2 = "SELECT rangefrom, rangeto, street, city,
precinctname, precnum
FROM Sheet1
WHERE CITY = '$city'
AND STREET LIKE('$street_no_return2')
AND RANGEFROM <= $street_number
AND RANGETO >= $street_number";
// prepare SQL statement
$no_return2 = odbc_prepare($connection,$sql_no_return2);
// execute SQL statement and get results
odbc_execute($no_return2);
$r = odbc_fetch_row( $no_return2 );
if ($r){
if ( $error_check ){
echo "checking on $street_no_return2 with city\n<br />\n";
}
get_precinct ($no_return2);
}
else { //CHECK 4
// create SQL statement
$sql_no_return3 = "SELECT rangefrom, rangeto,
street, city, precinctname, precnum
FROM Sheet1
WHERE STREET LIKE('$street_no_return2')
AND RANGEFROM <= $street_number
AND RANGETO >= $street_number";
// prepare SQL statement
$no_return3 =
odbc_prepare($connection,$sql_no_return3);
// execute SQL statement and get results
odbc_execute($no_return3);
$r = odbc_fetch_row( $no_return3 );
if ($r){
if ( $error_check ){
echo "checking on $street_no_return2 without
city\n<br />\n";
}
get_precinct ($no_return3);
}
else {
die ( "<H2>We're Sorry, but we could not find an
address match</H2>\n<br /> Please <a href=\"poll_locator.php\">Try
Again</a>\n" );
}
}
}
}
---------------------
John Asendorf - jasendorf@lcounty.com
Web Applications Developer
http://www.lcounty.com - CHECK OUT THE NEW LOOK!
Licking County, Ohio, USA
740-349-3631
> -----Original Message-----
> From: Foley, John [mailto:John.Foley@pollak.com]
> Sent: Tuesday, September 05, 2000 5:43 PM
> To: 'Asendorf, John'; php-windows@lists.php.net
> Subject: RE: [PHP-WIN] Quick One... determining if there are
> no results
> re turned
>
>
>
>
> ummm, doesn't PHP return FALSE or 0 if there are no
> rows returned .
> . . I seem to remember getting a lot of "0 is not a valid
> result identifier"
> messages early on!
>
> If this is the case, you can do what you are trying
> with just one
> call.
>
>
> John T. Foley
> Network Administrator
> Pollak Engineered Products, Actuator Products Division,
> A Stoneridge
> Company
> 195 Freeport Street, Boston MA 02122
> ph: (617) 474-7266 fax: (617) 282-9058
>
> The geographical center of Boston is in Roxbury. Due north of
> the center we find the South End. This is not to be confused
> with South
> Boston which lies directly east from the South End. North of
> the South
> End is East Boston and southwest of East Boston is the North End.
>
>
>
> > -----Original Message-----
> > From: Asendorf, John [SMTP:JAsendorf@lcounty.com]
> > Sent: Tuesday, September 05, 2000 11:13 AM
> > To: php-windows@lists.php.net
> > Subject: RE: [PHP-WIN] Quick One... determining if there are no
> > results re turned
> >
> > Hmmmm... I'm using odbc_num_rows ();
> >
> > and I always get -1
> >
> > any clues?
> >
> > ---------------------
> > John Asendorf - jasendorf@lcounty.com
> > Web Applications Developer
> > http://www.lcounty.com - CHECK OUT THE NEW LOOK!
> > Licking County, Ohio, USA
> > 740-349-3631
> >
> >
> > > -----Original Message-----
> > > From: Flint Doungchak [mailto:Flint@netsolutionsllc.com]
> > > Sent: Tuesday, September 05, 2000 10:52 AM
> > > To: 'Asendorf, John'
> > > Cc: php-windows@lists.php.net
> > > Subject: RE: [PHP-WIN] Quick One... determining if there are
> > > no results
> > > re turned
> > >
> > >
> > > Hello,
> > >
> > > Try using something like:
> > >
> > > $num = mysql_num_rows($SQL_request);
> > >
> > > $num will then equal the total number of rows returned. You
> > > can then use num
> > > in your if then else statements. I hope this is what you wanted.
> > >
> > > -Flint
> > >
> > > -----Original Message-----
> > > From: Asendorf, John [mailto:JAsendorf@lcounty.com]
> > > Sent: Tuesday, September 05, 2000 7:43 AM
> > > To: php-windows@lists.php.net
> > > Subject: [PHP-WIN] Quick One... determining if there are
> no results
> > > returned
> > >
> > >
> > > Here's a quick one... I wasted all my time finding chop() on
> > > my own this
> > > morning so someone has to help me find the expression I
> need here...
> > >
> > > I just need to know if the return from an SQL call is empty...
> > >
> > > e.g.
> > >
> > > if $SQL_request is empty {
> > > do one thing
> > > }
> > > else {
> > > do another thing
> > >
> > > }
> > >
> > > Anyone?
> > >
> > > ---------------------
> > > John Asendorf - jasendorf@lcounty.com
> > > Web Applications Developer
> > > http://www.lcounty.com - CHECK OUT THE NEW LOOK!
> > > Licking County, Ohio, USA
> > > 740-349-3631
> > >
> > > --
> > > PHP Windows Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-windows-help@lists.php.net
> > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > >
> > > --
> > > PHP Windows Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-windows-help@lists.php.net
> > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > >
>