dongnong3019 2015-01-31 14:57
浏览 55

如何在php和mysql中编写查询表

My dbLink Access:

dbusername:a4930120_query12
dbpassword:query12

http://sql6.000webhost.com/phpMyAdmin/index.php?db=a4930120_query12&lang=en-utf-8&convcharset=iso-8859-1&collation_connection=utf8_unicode_ci&token=d05f552925d40687254ceaee7c636758&phpMyAdmin=ucDEM,ggxf8kAny6Ki9LD0YSYqf.

I want to retrieve data based on subject and Class.column name for classes(Class_I_V Class_VI_VIII Class_IX_X Class_XI_XII).For example.my problem is how to write the search code for row no 8. they subject column contains(engg maths1,2,tpde,numerical methods,pqt,random pr...).like wise in my question is.Shall I want to give all keyword in my query(db column name is subject)?.if you see my subject column in my db.it contain all subject.I want to know how to write the proper code for this search.because user search with subject and class.As per my as per my level I have written the code.kindly make it proper. Here is my code:

<form name="f1" action="" method="post">
Enter the subject to search:
<input type="text" name="search" value="" />
<input type="submit" name="submit" value="submit"/>
</form>

search.php

<?php
if(isset($_POST['submit']))
{
$search=$_POST['search'];
$sql=mysql_query("SELECT name,subject,place,expyrs,Class_I_V FROM tutor WHERE subject LIKE '%$search%' or  subject LIKE '%$search%'  or  subject LIKE '%$search%' or subject LIKE '%$search%' or subject LIKE '%$search%' or subject LIKE '%$search%' or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%' Or Class_I_V LIKE '%Class I -V%' ");
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td><?php echo ++$sno; ?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['subject'];?></td>
<td><?php echo $row['place'];?></td>
<td><?php echo $row['expyrs'];?></td>
<td><?php echo $row['Class_I_V'];?></td>
</tr>
<?php
}
}
?>

Myurl:http://tutorquery.comuv.com/search.php

Type here:java or Class I -V

  • 写回答

1条回答 默认 最新

  • doumou1864 2015-01-31 15:13
    关注

    This may be a sort solution, try this way using REGEXP

     SELECT * FROM `tutor` 
       WHERE
     subject REGEXP '^(engg maths1|tpde|numerical methods|pqt|random)$' 
     OR Class_I_V REGEXP 'Class_I_V'
    

    See for more info that satisfy your requirements, http://dev.mysql.com/doc/refman/5.1/en/regexp.html

    EDIT Sorry at first i didn't see your database columns, i think you need Full Text Search in this case. see more here http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)