[英]Check if a row exists in database and if not display a message
I can't manage to check if a row exists in database and if not display a message. 我无法检查数据库中是否存在一行,如果不显示消息。 The code is below.
代码如下。 I need a little help.
我需要一点帮助。
<?php
$result = mysqli_query($mysqli, "SELECT client_cv FROM formular_client WHERE id = '$id'");
if (mysqli_num_rows($result) > 0){
echo "<a href='../cv/" . $rows['client_cv'] . "' target='_blank' class='btn btn-lg btn-primary'><span class='glyphicon glyphicon-download-alt'></span> Descarca CV</a>";
} else {
echo "<a href='#' target='_blank' class='btn btn-lg btn-primary'><span class='glyphicon glyphicon-download-alt'></span> Fara CV</a>";
}
?>
if you want to show different links based on if client_cv
has a value or not, try this 如果要基于
client_cv
是否具有值显示不同的链接,请尝试此操作
<?php
$result = mysqli_query($mysqli, "SELECT client_cv FROM formular_client WHERE id = '$id'");
if (mysqli_num_rows($result) > 0){
$rows = mysqli_fetch_array($result);
if (strlen($rows["client_cv"]) > 0){
echo "<a href='../cv/" . $rows['client_cv'] . "' target='_blank' class='btn btn-lg btn-primary'><span class='glyphicon glyphicon-download-alt'></span> Descarca CV</a>";
} else {
echo "<a href='#' target='_blank' class='btn btn-lg btn-primary'><span class='glyphicon glyphicon-download-alt'></span> Fara CV</a>";
}
} else {
echo "No record found"
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.