search page that allow user to select between three types using php mysql -
i have search page include 3 types of search , want filter search upon selecting types
- type 1 : newest members
- type 2 : specialization
- type 3 : name
specialization table:
- specialization_id
- specialization_name
members table :
- user_id
- first_name
- last_name
- specialization
- registered_date
but problem first type work fine second show members not selected specialization
the first query specialization selecting secialization drop list
the second join between sepcialization table , members tables can me ????
search.php
//************for specialization droplist***************************// function specializationquery(){ $specdata = mysql_query("select * specialization"); while($recordjob = mysql_fetch_array($specdata)){ echo'<option value="' . $recordjob['specialization_id'] . '">' . $recordjob['specialization_name'] . '</option>'; } } $outputlist = ""; //**********search new***************************************// if(isset($_post['searchbynew'])) { $listnew = $_post['searchbynew']; $sql = mysql_query("select * members registered_date!='' order 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 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 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 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 /> '; } }
you need where
clause in sql query.
select ... join ... u.specialization = '$selectedspec'
Comments
Post a Comment