[SOLVED]skipping a field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

[SOLVED]skipping a field

Post 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
Last edited by ol4pr0 on Thu Apr 15, 2004 1:02 pm, edited 1 time in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

if(count($row['pos']) > 0){
echo $row['pos'];
}
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 ;-(
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Doesnt really work tho...

Field is NULL, but it still appears on my screen

Any suggestions
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

if($row['pos'] != NULL){
echo $row['pos'];
}
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Sorry m8 didnt work either

Does it make a differance doing mssql instaead of a mysql query ?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Post your whole code.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

what is it echoing? are you sure that they're NULL? maybe there's whitespace
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try :
if(!empty($row['pos'])){
echo $row['pos'];
}
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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'];
}
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 )
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Could set the fields in the db to not allow NULL entries.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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].
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

Code: Select all

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