我想知道如何检查特定帖子的数据库是否没有输入标签,如果没有,则显示no tags have been entered
。我怎么能用PHP做到这一点?
这是我的PHP& MySQL代码。
$tag = array();
$dbc = mysqli_query($mysqli, "SELECT tags.tag
FROM posts_tags
INNER JOIN tags ON tags.id = posts_tags.tag_id
WHERE posts_tags.post_id = '" . $post_id . "'
GROUP BY tags.tag");
if (!$dbc) {
print mysqli_error($mysqli);
} else {
while($row = mysqli_fetch_array($dbc)){
$tag[] = $row['tag'];
}
}
答案 0 :(得分:1)
如果标签数组为空,则没有标签:
if(empty($tag)){
echo 'no tags have been entered';
}
您还可以检查返回的行数:
if(mysqli_num_rows($dbc) == 0){
echo 'no tags have been entered.';
}
答案 1 :(得分:0)
使用mysqli_num_rows
和代码如下:
$tag = array();
$dbc = mysqli_query($mysqli, "SELECT tags.tag
FROM posts_tags
INNER JOIN tags ON tags.id = posts_tags.tag_id
WHERE posts_tags.post_id = '" . $post_id . "'
GROUP BY tags.tag");
if (!$dbc)
{
print mysqli_error($mysqli);
}
elseif(!mysqli_num_rows($dbc))
{
echo "no tags have been entered";
}
else
{
while($row = mysqli_fetch_array($dbc))
{
$tag[] = $row['tag'];
}
print_r($tag);
}
答案 2 :(得分:0)
$(" .signup_name_image&#34)。隐藏();
var error_signup_name = false;
$(".signup_name").blur(function(){
check_signup_name();
});
function check_signup_name() {
var signup_name = $.trim($('.signup_name').val());
if (signup_name == '' || signup_name.length < 6 || signup_name.length > 50 ) {
$(".signup_name").css({"border":"1px solid #ff0000"});
$(".signup_name_image").show();
$(".signup_name_show").html("• Write Full Name in 6 to 50 alphabets");
**$(".signup_name").focus();**
error_signup_name = true;
} else if (/^[a-zA-Z0-9- ]*$/.test(signup_name) == false){
$(".signup_name").css({"border":"1px solid #ff0000"});
$(".signup_name_image").show();
$(".signup_name_show").html("• Contain invalid character");
**$(".signup_name").focus();**
error_signup_name = true;
}else {
$(".signup_name").css({"border":"1px solid #21cc00"});
$(".signup_name_image").hide();
}
}
$("#signup_form").submit(function(){
error_signup_name = false;
check_signup_name();
if (error_signup_name == false) {
return true;
} else {
return false;
}
});
$(".signup_name_image").hover(function(){
$(".signup_name_show").show();
}, function() {
$(".signup_name_show").hide();}
);
现在福克斯被困在同一领域 提交时如何关注字段