Page 1 of 2

[SOLVED]skipping a field

Posted: Mon Apr 12, 2004 6:21 pm
by ol4pr0
Basicly i want to know how to skip a field which does not contain any data.

Code: Select all

"SELECT * FROM $mssqltb WHERE id='" . $idc . "'"; 
// some other things...

echo $row['pos']; 

/*
if encounters a emtpy field dont echo 
*/
echo next $row

Posted: Mon Apr 12, 2004 6:33 pm
by d3ad1ysp0rk
if(count($row['pos']) > 0){
echo $row['pos'];
}

Posted: Mon Apr 12, 2004 6:38 pm
by ol4pr0
Thanks ( is there a global way of setting the if for all fields ?

or do i have to repeat that line over and over again ;-(

Posted: Mon Apr 12, 2004 6:46 pm
by ol4pr0
Doesnt really work tho...

Field is NULL, but it still appears on my screen

Any suggestions

Posted: Mon Apr 12, 2004 7:05 pm
by d3ad1ysp0rk
if($row['pos'] != NULL){
echo $row['pos'];
}

Posted: Mon Apr 12, 2004 7:30 pm
by ol4pr0
Sorry m8 didnt work either

Does it make a differance doing mssql instaead of a mysql query ?

Posted: Mon Apr 12, 2004 7:33 pm
by d3ad1ysp0rk
Post your whole code.

Posted: Mon Apr 12, 2004 7:33 pm
by andre_c
what is it echoing? are you sure that they're NULL? maybe there's whitespace

Posted: Mon Apr 12, 2004 7:37 pm
by markl999
Try :
if(!empty($row['pos'])){
echo $row['pos'];
}

Posted: Mon Apr 12, 2004 7:40 pm
by ol4pr0
The sql says <NULL>

snippet of code

Code: Select all

//$query = "SELECT * FROM $mssqltb WHERE id_courier='" . $idc . "'";
                                                                                                                            
 
// messing with store procedures mean while
$query = "sp_query_mandet01 " . $idc;
                                                                                                                             
$result = mssql_query($query);
if($row = mssql_fetch_array($result))
{


//snippet along the way.. everything else works
echo "<td bgcolor="#eeeeee" width="400" class="v"> ";
echo "<div class="r">Agent representante Transporte</div> ";
echo "</td>\n ";
echo "<td bgcolor="#eeeeee" width="600"> ";

Edit tried ALL options.. getting scared now that field might not be as NULL as sql says it is
// if($row['agente_representante_transporte'] != NULL){ 
//if(!empty($row['agente_representante_transporte'])){
if(count($row['agente_representante_transporte']) > 0){
echo $row['agente_representante_transporte'];
}

Posted: Tue Apr 13, 2004 6:22 am
by JAM
Why not simply:

Code: Select all

$query = "SELECT * FROM $mssqltb WHERE id_courier='" . $idc . "' and agente_representante_transporte is not null";
Or similiar?

Posted: Tue Apr 13, 2004 10:51 am
by ol4pr0
Becuase there are more than just that one ;-)

About 200 more of em... ( And they are not always empty. sometimes they have data sometimes they dont have data.. it can change everyday / everyhour )

Posted: Tue Apr 13, 2004 10:53 am
by kettle_drum
Could set the fields in the db to not allow NULL entries.

Posted: Tue Apr 13, 2004 6:03 pm
by JAM
ol4pr0 wrote:Becuase there are more than just that one ;-)

About 200 more of em... ( And they are not always empty. sometimes they have data sometimes they dont have data.. it can change everyday / everyhour )
Ahhhh! I was thinking the wrong way to disregard the rows that contains <NULL> in that field all together...

I'm however amazed that...

Code: Select all

if(count($row['agente_representante_transporte']) > 0){
...didn't work.

Try a:

Code: Select all

echo is_null($row['agente_representante_transporte']);
...somewhere. If it echo's 1 it's indeed NULL, if not, it's something else.

More here: [php_man]is_null[/php_man] and [php_man]gettype[/php_man].

Posted: Wed Apr 14, 2004 7:53 am
by liljester

Code: Select all

if(!is_null($row[whatever])){
     print"{$row[whatever]}\n";
}