本文介绍了搜索页面,允许用户使用php mysql在三种类型之间进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含三种搜索类型的搜索页面,我想根据选择的类型对搜索进行过滤
i have a search page that include three types of search and i want to filter the search upon the selecting types
- 类型1:最新成员
- 类型2:专业化
- 类型3:按名称
专业化表:
- specialization_id
- specialization_name
成员表:
- user_id
- 名字
- 姓氏
- 专业化
- 注册日期
但是第一种类型可以正常工作,但第二种类型却显示所有成员都没有所选专业化的问题
but the problem that the first type work fine but the second it show all members not the selected specialization
第一个专门化查询是从下拉列表中选择特殊化
the first query for the specialization is for selecting secialization from the drop list
第二个是在分隔表和成员表之间进行联接有人可以帮助我吗?
search.php
the second is to join between the sepcialization table and the members tablescan anyone help me ????
//************for specialization droplist***************************//
function specializationQuery(){
$specData = mysql_query("SELECT * FROM specialization");
while($recordJob = mysql_fetch_array($specData)){
echo'<option value="' . $recordJob['specialization_id'] . '">' . $recordJob['specialization_name'] . '</option>';
}
}
$outputlist = "";
//**********search by new***************************************//
if(isset($_POST['searchbynew']))
{
$listnew = $_POST['searchbynew'];
$sql = mysql_query("SELECT * FROM members WHERE registered_date!='' ORDER BY registered_date DESC ")or die((mysql_error("Error in quering new members List")));
while($row = mysql_fetch_array($sql))
{
$row_id = $row['user_id'];
$row_first_name = $row['first_name'];
$row_last_name = $row['last_name'];
$row_birthdate = $row['birth_date'];
$row_registered_date = $row['registered_date'];
////***********for the upload image*************************//
$check_pic="members/$row_id/image01.jpg";
$default_pic="members/0/image01.jpg";
if(file_exists($check_pic))
{
$user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
}
else
{
$user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
}
$outputlist.='
<table width="100%">
<tr>
<td width="23%" rowspan="3"><div style="height:120px;overflow:hidden;"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td>
<td width="14%"><div align="right">Name:</div></td>
<td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td>
</tr>
<tr>
<td><div align="right">Birth date:</div></td>
<td>'.$row_birthdate.'</td>
</tr>
<tr>
<td><div align="right">Registered:</div></td>
<td>'.$row_registered_date.'</td>
</tr>
</table>
<hr />
';
}//close while
}
if(isset($_POST['searchbyspec']))
{
$selectedSpec = $_POST['specialization'];
$sql = mysql_query("SELECT user_id,first_name, last_name, birth_date, registered_date, specialization_name
FROM members u INNER JOIN specialization s
ON u.specialization = s.specialization_id") or die(mysql_error("Error: quering thespecialization"));
while($row = mysql_fetch_array($sql))
{
$row_id = $row['user_id'];
$row_first_name = $row['first_name'];
$row_last_name = $row['last_name'];
$row_birthdate = $row['birth_date'];
$row_registered_date = $row['registered_date'];
$row_spec = $row['specialization_name'];
////***********for the upload image*************************//
$check_pic="members/$row_id/image01.jpg";
$default_pic="members/0/image01.jpg";
if(file_exists($check_pic))
{
$user_pic="<img src=\"$check_pic\"width=\"120px\"/>";
}
else
{
$user_pic="<img src=\"$default_pic\"width=\"120px\"/>";
}
$outputlist.='
<table width="100%">
<tr>
<td width="23%" rowspan="3"><div style="height:120px;overflow:hidden;"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td>
<td width="14%"><div align="right">Name:</div></td>
<td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td>
</tr>
<tr>
<td><div align="right">Birth date:</div></td>
<td>'.$row_birthdate.'</td>
</tr>
<tr>
<td><div align="right">Registered:</div></td>
<td>'.$row_registered_date.'</td>
</tr>
<tr>
<td><div align="right">Registered:</div></td>
<td>'.$row_spec.'</td>
</tr>
</table>
<hr />
';
}
}
推荐答案
SQL查询中需要 WHERE
子句.
You need a WHERE
clause in the SQL query.
SELECT ... JOIN ... WHERE u.specialization = '$selectedSpec'
这篇关于搜索页面,允许用户使用php mysql在三种类型之间进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!