在IF功能方面需要一些帮助

时间:2014-09-25 21:18:20

标签: php sql

我正在尝试建立一个关于足球队的网页。

所以,我把信息放在一个sql文件中,然后放在xampp数据库中。问题是,当我为这样的球员和教练提供信息时:http://i.imgur.com/6EuYNPh.png他们出现在' Stores'和'奖杯'也让它看起来很烦人:P http://i.imgur.com/tht9vTP.png

所以我需要一个代码,如IF市场价值或位置或出生地=空,然后隐藏这些值(我的意思是隐藏:市场价值,位置等)我知道我必须使用IF函数函数文件。我尝试了一些但实际上没有工作的东西。

我必须使用的确切代码是什么?我应该把它放在哪里?

函数文件在这里:

    <?php

//Position:    
//function to generate the local navigation bar for the bookstore web application

function gen_navigation(){
include("dbconnect.php");
echo "<head>";
echo '<link rel="stylesheet" type="text/css" href="css/navigation.css" />';
echo "</head>";
$query="select * from categories";
$result=mysql_query($query);
echo "<div id=navcontainer>";
echo "<ul id=navlist>";
while($row=mysql_fetch_array($result)){
echo "<li>";
echo "<a href=items.php?categoryid=";
echo $row['categoryid'];
echo ">";
echo $row['name'];
echo "</a>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
mysql_close();

}

//Position:    
//function to display the new items. The layout is formated by using tables

//position:    
//function to display the new items. The layout is formated by using tables
function showbooksbycat($categoryid=1,$offset=0,$limit=8){
if(empty($offset)){
    $offset=0;
    }
include("dbconnect.php");
$query="select * from items where categoryid=$categoryid order by isbn limit $offset,$limit";

$result=mysql_query($query);

echo "<br>";
while($row=mysql_fetch_array($result)){
echo "<table width=100% border=0>";
echo "<tr class=newitems>";
echo "<th>";
    echo "Market Value".$row['market value'];
    echo "</th>";
    echo "<th>";
        echo $row['name'];
        echo "</th>";
echo "</tr>";
echo "<tr>";
        echo "<td width=100>";
    echo "<img src=pictures/".$row['picture'].">";
    echo "</td>";
        echo "<td align=left>";
    echo "<p class=itemmaininf>";
echo "<b>Name:</b> ".$row['name']."<br>";
echo "<b>Position:</b> ".$row['position']."<br>";
echo "<b>Place Of Birth:</b> ".$row['birthplace']."<br>";
  echo "<b>Date Of Birth:</b> ".$row['date']."<br>";

echo "<b>Previous Clubs:</b> ".$row['previous clubs']."<br>";
echo "</p>";
        echo "<p class=footitem>";
    echo "</p>";
    echo "</td>";
    echo "</tr>";
 echo "</table>";
echo "<br>";
}
mysql_close();
}


function nav($categoryid=1,$offset=0,$limit=8){
include("dbconnect.php");
$query="select * from items where categoryid=$categoryid";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);



echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

if($offset>0){

echo "<a href=items.php?categoryid=".$categoryid."&offset=".($offset-$limit);
echo ">";
echo "<img border=0 src=pictures/prev.gif></a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

}

if($offset+$limit<$numrows){
echo "<a href=items.php?categoryid=".$categoryid."&offset=".($offset+$limit);
echo ">";
echo "<img border=0 src=pictures/next.gif></a>";
}
echo "</font>";
}
?>

1 个答案:

答案 0 :(得分:1)

基本方法是

更改

 echo "<b>Place Of Birth:</b> ".$row['birthplace']."<br>";

if(!empty($row['birthplace'])){ //! is not, so this says not empty
    echo "<b>Place Of Birth:</b> ".$row['birthplace']."<br>";
}