我想检查数据是否为空。这是空的,即使不是谷歌链接,也不会显示任何内容。如果有数据,则显示谷歌链接。我该如何解决?
$result = $mysqli->query("SELECT * FROM teams WHERE teamid = ".$_GET['teamid']." ORDER BY `teamname` DESC");
$teamdetails = mysqli_fetch_assoc($result);
echo '<table id=kalender_table><tr><td><h3>'.$teamdetails['teamname'].'</h3> <br>';
echo ''.$teamdetails['teamid'].'<br>';
echo '<a href="'.$teamdetails['website'].'" target="_blank">'.$teamdetails['website'].'</a> <br></td>';
echo '<td><img src=../../logo/'.$teamdetails['image'].'></td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_name'].'</td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_adress'].'</td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_zip'].' '.$teamdetails['cmp1_city'].'</td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_phone'].'</td></tr>';
echo '<tr><td colspan="2"><a href="https://www.google.be/maps/place/'.$teamdetails['cmp1_adress'].'+'.$teamdetails['cmp1_zip'].'+'.$teamdetails['cmp1_city'].'" target="_blank">Google maps</a></td></tr>';
答案 0 :(得分:1)
你可以试试这个:
<?php
if (is_array($teamdetails) && count($teamdetails) > 0) {
// Do something
}
答案 1 :(得分:1)
简单地使用行计数,如果大于0则显示,如果没有,则无需显示
$result = $mysqli->query("SELECT * FROM teams WHERE teamid = ".$_GET['teamid']." ORDER BY `teamname` DESC");
$teamdetails = mysqli_fetch_assoc($result);
if((mysqli_num_rows($result) > 0) {
echo '<table id=kalender_table><tr><td><h3>'.$teamdetails['teamname'].'</h3> <br>';
echo ''.$teamdetails['teamid'].'<br>';
echo '<a href="'.$teamdetails['website'].'" target="_blank">'.$teamdetails['website'].'</a> <br></td>';
echo '<td><img src=../../logo/'.$teamdetails['image'].'></td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_name'].'</td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_adress'].'</td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_zip'].' '.$teamdetails['cmp1_city'].'</td></tr>';
echo '<tr><td colspan="2">'.$teamdetails['cmp1_phone'].'</td></tr>';
echo '<tr><td colspan="2"><a href="https://www.google.be/maps/place/'.$teamdetails['cmp1_adress'].'+'.$teamdetails['cmp1_zip'].'+'.$teamdetails['cmp1_city'].'" target="_blank">Google maps</a></td></tr>';
} else {
echo '<tr><td colspan="2">'Nothing to Show'</td></tr>';
}
答案 2 :(得分:0)
:
if (mysqli_affected_rows()){
...
}
答案 3 :(得分:-1)
您需要使用“isset”函数,因为使用count()可能存在行但其中没有数据。
[...]
$teamdetails = mysqli_fetch_assoc($result);
if (isset($teamdetails['teamname']) & $teamdetails['teamname']) {
echo '<table id=kalender_table><tr><td><h3>'.$teamdetails['teamname'].'</h3> <br>';
[...]
}
[...]