dongyou8087 2013-01-21 20:33
浏览 86

php mysql在同一个表中查找具有相同数据的多行

Hi I've been searching for this now for a few days and can't seem to get it right, hoping someone might be able to lend a hand. Here is the scenario:

techinfo table

repid fname lname region
1234  bob   smith  NY
4567  bob   sacamano toronto
3478  bob   hill   texas
9876  bob   underwood vancouver
7345  tom   tucker  halifax
2357  bill  shatner  LA

I am trying to find all of the bobs based on the input field looking for repid, first name, last name, etc...

basiacally if somone types bob into the form it should return all info for all the bobs.

I am totally stuck on this.

i have gotten to the point of determining if there is a bob record and can pull one, but i can't pull multiples.

here are some of the code snippets for example. any help is greatly apprecaited.

$MetaQuery="SELECT * FROM `techinfo` WHERE repid='$_POST[repid]' OR fname='$_POST[fname]'";
$MetaResults=mysql_query($MetaQuery, $DBconnect);
if(mysql_num_rows($MetaResults)>0)
{   
/*
quick check of array storage
*/
 echo "<br>we found results:".$row['repid']. $row['fname']. $row['lname'];
 }
  • 写回答

1条回答 默认 最新

  • duan0708676887 2013-01-21 20:38
    关注

    1) mysql_ functions are being depericated use PDO

    2) please learn about sql injection

    3 mysql_query returns a resource that has to be looped though eg.

    while($row = mysql_fetch_assoc($MetaResults) {
        echo "<br>we found results:".$row['repid']. $row['fname']. $row['lname'];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序