验证记录是否存在的数据库条件


Validating database condition for record existance

在我的网站上,我有textbox用户输入 URL 的位置。

Onece用户输入它,我显示该URL的预览,其中包含该URL上的图像和小描述。

我从数据库中获取预览详细信息。

场景是这样的:

1. user enters url
2. Check whether url exist in table
3. If yes dont inset into db and fetch details like url title, desc, image
4. If not exist insert into table and then show the preview from it

那么如何首先检查它是否存在于表中呢?

$url检查条件。

select url from post_record where url='".$url."';

我想要此查询的布尔值或 1/0 结果。我怎样才能得到它?如果为 True,那么如果结果为 0,我直接获取记录,然后我首先输入详细信息,然后显示表中的预览。

这是正确的方式还是有人可以想到的更好的场景。

只需选择COUNT()

SELECT COUNT(*) FROM post_record WHERE url = ?
从 URL

= user_inputted_value post_record中选择 COUNT(*)

这是对的吗?

    $result = mysqli_query("SELECT url from post_data where url='".$url."' and id='".$id."'");
        if ($url = @mysqli_fetch_array($result))
        {
            // do nothing
        }
        else
        {
            //insert url details
        }
            //After this fetch data from table to show preview