Connecting Tech Pros Worldwide Forums | Help | Site Map

if fetch array is empty ?

Sylvie Stone
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi All -

I'm doing a fetch_array and I would like to display a "no records
found" message to screen. For some reason this is not working:

here's my Postgres SQL as proof:
surveys=# select othermore from table where othermore <> '';
othermore
-----------
(0 rows)

Then I have:
$result = pg_query($conn, "select othermore from table where
othermore <> ''");
while ($row = pg_fetch_array($result)) {
if (!$result) {
echo "no records<br>\n";
} else {
echo "$row[0]<br>";
}
}

Strnage ? Can someone shed some light on what UI am doing wrong ?

THANKS

Sylvie.

Jon Kraft
Guest
 
Posts: n/a
#2: Jul 17 '05

re: if fetch array is empty ?


Sylvie Stone <sylviestone@canada.com> wrote:
[color=blue]
> I'm doing a fetch_array and I would like to display a "no records
> found" message to screen. For some reason this is not working:
>[/color]
[color=blue]
> $result = pg_query($conn, "select othermore from table where
> othermore <> ''");[/color]

$numRows = pg_num_rows($result);
if($numRows==0){
echo "No records found";
}
else{
while ($row = pg_fetch_array($result)) {
//....
}
}

Check the amount of rows returned with pg_num_rows:
http://uk.php.net/manual/en/function.pg-num-rows.php

HTH;
JOn
BKDotCom
Guest
 
Posts: n/a
#3: Jul 17 '05

re: if fetch array is empty ?


hmm... you've gone wrong in a couple ways. :)
pg_query will only return false if there's an error with your query or
couldn't connect, or whatever.

$result = pg_query($conn, "select othermore from table where othermore
<> ''");
if ( !$result )
echo 'error! - abort abort';
else {
while ($row = pg_fetch_array($result)) {
echo $row[0].'<br>';
}
}

sylviestone@canada.com (Sylvie Stone) wrote in message news:<181a24a8.0309170613.421bd49@posting.google.c om>...[color=blue]
> Hi All -
>
> I'm doing a fetch_array and I would like to display a "no records
> found" message to screen. For some reason this is not working:
>
> here's my Postgres SQL as proof:
> surveys=# select othermore from table where othermore <> '';
> othermore
> -----------
> (0 rows)
>
> Then I have:
> $result = pg_query($conn, "select othermore from table where
> othermore <> ''");
> while ($row = pg_fetch_array($result)) {
> if (!$result) {
> echo "no records<br>\n";
> } else {
> echo "$row[0]<br>";
> }
> }
>
> Strnage ? Can someone shed some light on what UI am doing wrong ?
>
> THANKS
>
> Sylvie.[/color]
Closed Thread