如果数据库没有记录,显示回显?

时间:2016-05-01 02:04:40

标签: php mysql

所以我已经创建了一个Profile类型的东西,状态更新,但是,当数据库中没有状态时,它显示空白当然,我试图这样做,如果数据库是empty,然后echo "You have no Feed"这是我的代码:

<?php 
$status = mysql_query("SELECT * FROM status WHERE user='$username' ORDER BY date DESC");
while($row = mysql_fetch_array($status))

if($row['user'] == '') { echo "You have no Feed"; } else {

{

echo "<table width='520'>";
echo  "<tr>";
echo    "<td width='53' height='57'  valign='top' rowspan='3'><img src='../includes/images/profile/$image' height='50px' width='50px' style='border: 1px solid #000'></td>";
echo    "<td width='411' valign='top'><font color='#CCCCCC'>". $row['sentby'] . "</font><br><font size='1px' color='#CCCCCC'>". $row['date'] . "</font></td>";
echo  "</tr>";
echo  "<tr>";
echo    "<td></td>";
echo  "</tr>";
echo "<tr>";
echo  "<td>";
echo "</td>";
echo "</tr>";
echo  "<tr>";
echo    "<td colspan='2' valign='top'><font color='#CCCCCC'>". $row['status'] . "</font></td>";
echo   "</tr>";
echo "</table>";
echo "</p>"; 

}
}

?>

我的个人资料的工作方式是,每个人都有自己的个人资料,如果你去找某个人的个人资料并评论他们的&#34;墙&#34;当然,它只会停留在墙上,我的数据库创建为'id' 'status' 'user' 'sentby' 'user' (being the username of who's wall it was posted on)'sentby' (to display who sent it)

基本上,如果找不到用户名,我需要'user'列匹配,如果找不到用户名,则回复邮件。

1 个答案:

答案 0 :(得分:1)

mysql_num_rows函数将返回查询提取的行数。这应该工作。

try (Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Records", "postgres", "21262050")) {
    JavaApplication8 dc = new JavaApplication8();
    String sql = "INSERT INTO records (start_date,hour,cell_name,Erlang,ErlangU,cell_type,freq_type) VALUES ( ?,?,?,?,?,?,? )";
    try (PreparedStatement pst = c.prepareStatement(sql)) {
        pst.setInt(1, dc.time());
        pst.setInt(2, heure);
        pst.setString(3, "fgf");
        pst.setFloat(4, 84 / 10);
        pst.setFloat(5, dc.Hourly_Traffic_900);
        pst.setInt(6, 1);
        pst.setInt(7, 900);
        pst.executeUpdate();
    }
} catch (SQLException e) {
    System.err.println(e.getClass().getName() + ": " + e.getMessage());
    System.exit(0);
}
System.out.println("Records created successfully");