Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Apr 12, 2004 6:21 pm
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 » Mon Apr 12, 2004 6:33 pm
if(count($row['pos']) > 0){
echo $row['pos'];
}
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Apr 12, 2004 6:38 pm
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 ;-(
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Apr 12, 2004 6:46 pm
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 » Mon Apr 12, 2004 7:05 pm
if($row['pos'] != NULL){
echo $row['pos'];
}
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Apr 12, 2004 7:30 pm
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 » Mon Apr 12, 2004 7:33 pm
Post your whole code.
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Mon Apr 12, 2004 7:33 pm
what is it echoing? are you sure that they're NULL? maybe there's whitespace
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Apr 12, 2004 7:37 pm
Try :
if(!empty($row['pos'])){
echo $row['pos'];
}
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Apr 12, 2004 7:40 pm
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'];
}
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Tue Apr 13, 2004 6:22 am
Why not simply:
Code: Select all
$query = "SELECT * FROM $mssqltb WHERE id_courier='" . $idc . "' and agente_representante_transporte is not null";
Or similiar?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue Apr 13, 2004 10:51 am
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 » Tue Apr 13, 2004 10:53 am
Could set the fields in the db to not allow NULL entries.
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Tue Apr 13, 2004 6:03 pm
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].
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Wed Apr 14, 2004 7:53 am
Code: Select all
if(!is_null($row[whatever])){
print"{$row[whatever]}\n";
}