bp_travis
05-29-2007, 04:01 PM
Hello there. I am trying to use PHP to display a list of comapanies in a database. The problem is that I want to display a companies 800 number and fax number, but not every company has an 800 number of fax number. I am trying to figure out how to make PHP determine if there is data in that column, to print it, but otherwise, don't print it. Here is a portion of the code.
$sql="SELECT * FROM buyers_guide_companies";
$result=mysql_query($sql,$db);
$row=mysql_fetch_array($result);
$other_number="SELECT 800_number FROM buyers_guide_companies";
$result2=mysql_query($other_number,$db);
$row2=mysql_fetch_array($result2);
do{
printf("<h1>%s</h1><p>",$row['company_name']);
if($row2=mysql_fetch_array($result2)){
printf(" %s <br />",$row2['800_number']);
}else{
echo"problem";
}
printf("%s<br />",$row['regular_number']);
printf("Fax:%s",$row['fax']);
printf("<a href=\"mailto:%s\">%s</a> <br />",$row['email'],$row['email']);
printf("<a href=\"http://%s\">%s</a><br />",$row['website'],$row['website']);
printf("<em>%s</em><br />",$row['pres']);
printf("<em>%s</em></p>",$row['mkg_mrg']);
}while($row=mysql_fetch_array($result));
The problem is, that the if statement always comes out true and never false, even though some companies don't have those numbers. Thanks.
$sql="SELECT * FROM buyers_guide_companies";
$result=mysql_query($sql,$db);
$row=mysql_fetch_array($result);
$other_number="SELECT 800_number FROM buyers_guide_companies";
$result2=mysql_query($other_number,$db);
$row2=mysql_fetch_array($result2);
do{
printf("<h1>%s</h1><p>",$row['company_name']);
if($row2=mysql_fetch_array($result2)){
printf(" %s <br />",$row2['800_number']);
}else{
echo"problem";
}
printf("%s<br />",$row['regular_number']);
printf("Fax:%s",$row['fax']);
printf("<a href=\"mailto:%s\">%s</a> <br />",$row['email'],$row['email']);
printf("<a href=\"http://%s\">%s</a><br />",$row['website'],$row['website']);
printf("<em>%s</em><br />",$row['pres']);
printf("<em>%s</em></p>",$row['mkg_mrg']);
}while($row=mysql_fetch_array($result));
The problem is, that the if statement always comes out true and never false, even though some companies don't have those numbers. Thanks.