473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how can I check a recordset is null or not?

pam
sorry for my poor english first.

$notation=$rs->fields["notation"];
if(!empty($notation))
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 15399
In mysql you can use ISNULL(field_name) 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*********************@l41g2000cwc.googlegro ups.com...
sorry for my poor english first.

$notation=$rs->fields["notation"];
if(!empty($notation))
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($notation))
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_assoc(). Manual says:

"mysql_fetch_assoc [...] 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_assoc(), I'm using a access
database now,

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

<table bgcolor="#FFFFFF" cellspacing="1" width="100%" align="center">
<tr>
<th class="tables" width="10%">id</th>
<th class="tables" width="20%">brand</th>
<th class="tables" width="10%">type</th>
<th class="tables" width="10%">color</th>
<th class="tables" width="10%">size</th>
<th class="tables" width="50%">notation</th>
</tr>
<?php
for($i=1;$i<=$rs->pagesize;$i++){
?>
<tr bgcolor="#DEE7EF" 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_assoc(), I'm using a access
database now, [...] for($i=1;$i<=$rs->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={Microsoft Access Driver (*.mdb)};
DBQ=D:/pam/web/php/clothes/clothes.mdb";
$conn = new com("ADODB.Connection");
$conn->Open($connstr);
$rs = new com("ADODB.Recordset");
$sqltext = "SELECT clothes.id, brand.brand, type.type,
clothes_type.color, clothes_type.size, clothes.notation FROM type INNER
JOIN ((brand INNER JOIN clothes_type ON brand.id = clothes_type.brand)
INNER JOIN clothes ON clothes_type.model = clothes.typeid) ON type.id =
clothes_type.type";

$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.Recordset");


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
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...
2
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...
2
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...
1
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
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...
15
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
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...
1
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...
11
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. ...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.