On my site, I have textbox
where user enters URL.
Onece user enters it I show preview of that url, which contains image on that url and small description.
I fetch preview details from database.
Scenario is like this:
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
So how first I can check whether it is present in table or not?
I have $url
to check the condition.
select url from post_record where url='".$url."';
I want bool or 1/0 result for this query. How can I get it? If True then I directly fetch record if result is 0 then I first enter the details and then show preview from table.
Is this correct way or better scenario someone can think.
Just select the COUNT()
:
SELECT COUNT(*) FROM post_record WHERE url = ?
SELECT COUNT(*) FROM post_record WHERE url = user_inputted_value
Is this correct?
$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