473,806 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can I check a recordset is null or not?

pam
sorry for my poor english first.

$notation=$rs->fields["notation"];
if(!empty($nota tion))
echo $notation;

the notation field in database is a text type, when the value is null,
it will cause a mistake;
i used empty function to check it, but it seems don't take effect.

Jul 17 '05 #1
6 15466
In mysql you can use ISNULL(field_na me) to see if it's null or not... might
help ya.

-Mike

--
Melt away the Cellulite with Cellulean!
http://www.MeltAwayCellulite.com/
"pam" <pe******@gmail .com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
sorry for my poor english first.

$notation=$rs->fields["notation"];
if(!empty($nota tion))
echo $notation;

the notation field in database is a text type, when the value is null,
it will cause a mistake;
i used empty function to check it, but it seems don't take effect.

Jul 17 '05 #2
*** pam wrote/escribió (25 Apr 2005 19:31:52 -0700):
$notation=$rs->fields["notation"];
if(!empty($nota tion))
echo $notation;

the notation field in database is a text type, when the value is null,
it will cause a mistake;
i used empty function to check it, but it seems don't take effect.


You don't give much info. Let's suppose you get your recordset through
mysql_fetch_ass oc(). Manual says:

"mysql_fetch_as soc [...] Returns an associative array that corresponds to
the fetched row, or FALSE if there are no more rows."

"This function sets NULL fields to PHP NULL value."

So:

How to check if a recordset is null or not? Test if $rs is FALSE:

if($rs){ ... }

How to check if a field is null or not? Test if $rs['field'] is NULL:

if(!is_null($rs['field'])){ ... }
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3
pam
sorry, I don't know what it is mysql_fetch_ass oc(), I'm using a access
database now,

i can't express it clearly in english, so I paste more code.

<table bgcolor="#FFFFF F" cellspacing="1" width="100%" align="center">
<tr>
<th class="tables" width="10%">id</th>
<th class="tables" width="20%">bra nd</th>
<th class="tables" width="10%">typ e</th>
<th class="tables" width="10%">col or</th>
<th class="tables" width="10%">siz e</th>
<th class="tables" width="50%">not ation</th>
</tr>
<?php
for($i=1;$i<=$r s->pagesize;$i++) {
?>
<tr bgcolor="#DEE7E F" align="center">
<td class="tables"> <?php echo $rs->fields["id"]?></td>
<td class="tables"> <?php echo $rs->fields["brand"]?></td>
<td class="tables"> <?php echo $rs->fields["type"]?></td>
<td class="tables"> <?php echo $rs->fields["color"]?></td>
<td class="tables"> <?php echo $rs->fields["size"]?></td>
<td class="tables"> <?php if(!is_null($rs->fields["notation"])) echo
$rs->fields["notation"];?></td>
</tr>
<?php
$rs->movenext;
if($rs->eof) break;
}

i used a is_null function in it, but it still has mistake,
when I delete this line:echo $rs->fields["notation"];
It will work no problem, and i set a value in notation fields, it can
work also, only when the value is null, it will cause a mistake,I don't
know how to check the recordset is null.

Jul 17 '05 #4
*** pam wrote/escribió (26 Apr 2005 03:33:53 -0700):
sorry, I don't know what it is mysql_fetch_ass oc(), I'm using a access
database now, [...] for($i=1;$i<=$r s->pagesize;$i++) {


I insist: find out where $rs comes from and read its manual page.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #5
pam
i copyed the code about where $rs comes from.

global $conn;
$connstr = "DRIVER={Micros oft Access Driver (*.mdb)};
DBQ=D:/pam/web/php/clothes/clothes.mdb";
$conn = new com("ADODB.Conn ection");
$conn->Open($connstr) ;
$rs = new com("ADODB.Reco rdset");
$sqltext = "SELECT clothes.id, brand.brand, type.type,
clothes_type.co lor, clothes_type.si ze, clothes.notatio n FROM type INNER
JOIN ((brand INNER JOIN clothes_type ON brand.id = clothes_type.br and)
INNER JOIN clothes ON clothes_type.mo del = clothes.typeid) ON type.id =
clothes_type.ty pe";

$rs->open($sqltext, $conn,1,1);

It will works no problem when I the value is not null, so I think it
won't be the recordset is null.

Jul 17 '05 #6
*** pam wrote/escribió (26 Apr 2005 04:08:11 -0700):
$rs = new com("ADODB.Reco rdset");


Right, we're getting closer. You're instantiating an OLE compatible COM
object. That means that you should read the object's API documentation
since PHP has nothing to do with it :(

Now you need to make sure you understand some database concepts:

* A recordset is a matrix that contains the complete result of a query
* A row (or record) is one line of the recordset
* A column (or field) if one item of the row

So, what's your problem with? Recordsets, rows or columns?

Given that your problem comes with NULL columns, I suggest you investigate
the following functions and operators:

gettype()
print_r()
is_null()
===
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #7

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

Similar topics

1
45743
by: Luis | last post by:
Is there an easier way to check if any of the fields returned in a select statement have null values? After running this command: set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from SomeTable where...") I could check each field this way:
2
13890
by: sam | last post by:
For Example, If I delete two times like the below code, the program will behave differently. is this correct? As C++ FAQ the delete checks where or not f1 has memory. How can the following program can go wrong? class foo{ // }; int main{ foo *f1 = new foo()
2
3966
by: ad | last post by:
I have a string like string sNo. I want to cast it to int with int.Parse(sNo) but if the string is null or empty, it will thow exception. I must check if sNo is not null and is not empty before cast like: if ((sNo<>null) && (sNo<>"")) Have there any function to check the null and "" at once
1
4292
by: MattH | last post by:
I can't seem to figure out the syntax for checking for null values in asp.net. Can anyone point me in the right direction? Also, is there a common area on the MSDN for syntax lookup? Thanks!
1
1282
by: WebBuilder451 | last post by:
Why will this not work? it comes back with an error saying it can't work because the value is null this is a dataset value retreaved from db and it is null. call to check for null Me.txtExtra1.Text = Me.MNS(.usrExtra1) function to return a default value: Public Function MNS(ByVal s As Object) As String If IsDBNull(s) Then Return String.Empty
15
128314
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
4
4645
by: Richard Coltrane | last post by:
Hi there, Im stepping into C# from VB.net. In all the examples ive seen about raising events the following construct is used: if (myevent != null) myevent(this,args); Whats the purpose of the test for null? Is that testing to see if the underlying delegate is null? If so when would it be?
1
1821
by: Sparky74 | last post by:
Hi Everybody. I have been searching for many hours for an answer to this problem. I hope somebody can help me. I have a C# .NET client application that connects to a TCP/IP C++ server application that I have maintained for a number of years. What I am finding is that Socket.Close() does not actually sever the client connection from my server application. Actually, my statement above isn't entirely true - Socket.Close() *does* work as...
11
13388
by: questionit | last post by:
Dlookup() gives an error if the searchkey (the field i am looking for) is not found in the table. How to check before Dlookup() statement whether the table contains the required value. Similarly, with DAO RecordSet : Set rst = db.OpenRecordset("Select name FROM Table1 WHERE name='" & "AName" & "'") MsgBox rst.Fields("name") <--------------------- Get error here if "AName" not returned from the table.
2
14667
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the following code passes string.Empty as parameter but how to pass null value?), I cannot check for null value...
0
9719
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
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10624
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...
0
10111
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
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
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
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.