dtxooq1020 2013-10-30 09:51
浏览 14

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

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.

  • 写回答

3条回答 默认 最新

  • duanchuang3182 2013-10-30 09:55
    关注

    Just select the COUNT():

    SELECT COUNT(*) FROM post_record WHERE url = ?
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题