473,659 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

if fetch array is empty ?

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.
Jul 17 '05 #1
2 8786
Sylvie Stone <sy*********@ca nada.com> wrote:
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:
$result = pg_query($conn, "select othermore from table where
othermore <> ''");


$numRows = pg_num_rows($re sult);
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
Jul 17 '05 #2
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>';
}
}

sy*********@can ada.com (Sylvie Stone) wrote in message news:<18******* *************** ***@posting.goo gle.com>...
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.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1913
by: | last post by:
Hi All, I have designed a debit-system database with a PHP frontend. The amounts need to be updated on a monthly basis. now i have 10 clients in the system. i can get all the fields and display them, but next to that, i need to insert a field where we can enter an amount per client and after all the new amounts have been filled in, i need to update the database with those amounts entered. I know that by using html forms to enter the...
4
2954
by: Marcel Brekelmans | last post by:
Hello, I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example: I have a simple table 'tblName': ID Name 1 Jane 2 Joe 2 Doe
1
2810
by: yasmine | last post by:
Hi friends, I'm having a table which stores id as comma separated in string datatype. I want to fetch each of the value in a row in the form of array such as follows: table: sid name 2,3,5,7,9... Apple 19,37,46,1... Orange
5
3220
by: meeanji | last post by:
Dear friends, I am storing values in Array. My array looks like this:: balu 26 MCA gold -------------> first row of array amar 27 MBA gold -------------> 2nd row of array raja 28 MSC gold -------------> 3rd row of array
14
2619
by: Dan Rumney | last post by:
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = ; as opposed to using a constructor var arr2 = new Array(); I've been a-googling, but the best reason for this that I can find is
2
1458
by: teser3 | last post by:
For the below query: ---------- $res = mysql_query("select * from tableOne where clientID='". $_GET."'") or die(mysql_error()); if($inf = mysql_fetch_array($res) ----------------- The return from this ($inf = mysql_fetch_array($res) looks like this: $inf $inf $inf
8
5843
by: Sunny | last post by:
Hi, Can someone tell me, How to redefine array or make array empty or null. Here what I am trying to do. var temp = new Array(); for(i=0; i <=outstring.length-1; i++) { temp = outstring.split(','); } Once the for loop will finish doing it, I want temp array to be null
3
2301
ddtpmyra
by: ddtpmyra | last post by:
I have two separate query on my PHP mailer and I wonder how can it be possible to call the two queries in one fetch array. #email process starts here require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->From = "xxxx"; $mail->FromName = "administrator";
1
3214
by: BinaryBird | last post by:
Hi, i have a small script to display records from two tables. Table 1 keeps track of teams and table 2 keeps track of the members. <?php $dl = mysql_connect ("localhost","nitin_nick","test1234"); $db = mysql_select_db("nitin_registration",$dl); echo "<table border='0' width='986' align='center' cellspacing='1' cellpadding='5'>"; echo "<tr>"; echo "<th>Team Name</th>";
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.