dss89001 2016-06-08 19:36
浏览 20
已采纳

如何在PHP MySQL中构建查询字符串

I'm building my php application that relates with a MySQL database. I have some problems doing specific queries since i'm not used doing complex ones. I want to find out how to build query string to do this: Based on "cad_proc" "sigla" i want to get "estado" from "juizo" to make sure that i'm looking for "cad_proc" that have "MG" on it.

Table1: cad_proc               
id - sigla  - ...             
01 - MG105  - ...                        
03 - M123   - ...            
Table2: juizo
sigla - estado -...
MG105 - MG
M123  - MG

My query so far is:

SELECT * FROM cad_processo WHERE sigla like '$UF';

Where $UF is an input from user.

  • 写回答

4条回答 默认 最新

  • douguo6472 2016-06-08 19:53
    关注

    I think this is your desired result

    Select card_proc.*, juizo.estado from card_proc left join juizo on (card_proc.sigla=juizo.sigla) where card_proc.sigla like '%$UF%'
    

    Or if you want to do exact match..

    Select card_proc.*, juizo.estado from card_proc left join juizo on (card_proc.sigla=juizo.sigla) where card_proc.sigla = '$UF'
    

    Updated query..

     Select card_proc.* from card_proc left join juizo on (card_proc.sigla=juizo.sigla) where juizo.estado = '$UF'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题