Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test null recordset value 2

Status
Not open for further replies.

clivehenderson

IS-IT--Management
Nov 2, 2002
66
GB
Hi
I've just managed to create a joined recordset with a mixture of values and nulls in the recordset fields.
This was my intention and I now need to be able to test if field has a null value null value for example


if (@$row_rsCourt1['bookingID'] = null) {
?>
<span class="courtFree">FREE</span>
<?php
// else Conditional region1
} else { ?>
<span class="courtBooked">BOOKED</span>
<?php }
The 'else' part of the statement is always executed.

I've tried concatenating the nullfield with a letter but it still returns a null value

Not sure what else to do

Appreciate any help on this
kind regards
Clive
 
Hi

Clive said:
I now need to be able to test if field has a null value
SQL:
[b]select[/b] [teal]*[/teal] [b]from[/b] table [b]where[/b] field [highlight][b]is[/b] [b]null[/b][/highlight][teal];[/teal]
Clive said:
I've tried concatenating the nullfield with a letter but it still returns a null value
SQL:
[b]select[/b] concat[teal]([/teal][highlight]coalesce[teal]([/teal][/highlight]field[highlight][teal],[/teal][green][i]''[/i][/green][teal])[/teal][/highlight][teal],[/teal][green][i]'letter'[/i][/green][teal])[/teal] [b]from[/b] table[teal];[/teal]
By the way, what kind of SQL ?

By the way, how is this related to PHP ?

Two advices :
Clive said:
if (@$row_rsCourt1['bookingID'] = null) {
[ul]
[li]Add the [tt]@[/tt] operator only after you are sure your code is correct and functional.[/li]
[li]Setting a variable to [tt]null[/tt] will be always evaluated to false. ( The equality test operator is [tt]==[/tt] . )[/li]
[/ul]


Feherke.
 
If your using mySql
select ifnull(bookingID,0) as bookingID from ....


To do it in PHP
if((is_null(@$row_rsCourt1['bookingID'])?0,@$row_rsCourt1['bookingID'])!=0)
{
?>
<span class="courtFree">FREE</span>
<?php
// else Conditional region1
} else { ?>
<span class="courtBooked">BOOKED</span>
<?php }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top