472,146 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 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 15152
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Luis | last post: by
1 post views Thread by MattH | last post: by
1 post views Thread by WebBuilder451 | last post: by
15 posts views Thread by Tarun Mistry | last post: by
4 posts views Thread by Richard Coltrane | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.