jimjack145 Posted March 21, 2007 Share Posted March 21, 2007 Hi All, I have tabel called "candidate" in that i have two fields call Graduation Passing year and Post Graduation Passing year. In that table i have more than thousands number of candidate. Here i want to make a search php form. Where i can get data of specific candidate who pass between specific year. I have make a form for search with below fields: Graduation Candidate search : Year From and Year To fields and submit button to call query form and display result. however i tried my end but not able to make such query into Mysql. Please help me make mysql query to display candidate as per my year criteria search. Jimi --------------- Here is first search.php code // search Graduation result Graduation candidate seach<BR> <form name="search1" action="graduation.php" method=post> From : <input type=text size="10" name=from value=""> <BR><BR> To : <Input type=text size="10" name=to value=""><BR><BR> <center><input type="submit" value="Submit"></center> </form> --------------- 2) gaduation.php <?php $loginname = ""; $password = ""; $database = ""; $con = mysql_connect("localhost", "$loginname", "$password") or die("could not connect"); mysql_select_db("$database"); $query = "SELECT * FROM candidate_foreign WHERE value BETWEEN" .$_post['from']. "AND '".$_post['to']."'"; $result = mysql_query ("$query"); echo"<table border=1><TH>Year</TH>"; while ($in = mysql_fetch_array($result)) { echo"<tr>"; echo"<td>". $in['value'] . "<td>"; echo"</tr>"; } echo "</table>"; mysql_close($con); ?> --------------------- Getting error as - Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/graduation.php on line 18 Please help me to get appropriate result from the query. Jimi Link to comment https://forums.phpfreaks.com/topic/43638-search-data-between-two-specific-year/ Share on other sites More sharing options...
skali Posted March 21, 2007 Share Posted March 21, 2007 $result = mysql_query ("$query"); echo"<table border=1><TH>Year</TH>"; //add this line if(mysql_num_rows($result)){ while ($in = mysql_fetch_array($result)){ } } Link to comment https://forums.phpfreaks.com/topic/43638-search-data-between-two-specific-year/#findComment-211871 Share on other sites More sharing options...
jimjack145 Posted March 21, 2007 Author Share Posted March 21, 2007 After adding that line its give an error as below: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/graduation.php on line 17 Jimi Link to comment https://forums.phpfreaks.com/topic/43638-search-data-between-two-specific-year/#findComment-211874 Share on other sites More sharing options...
skali Posted March 21, 2007 Share Posted March 21, 2007 $query = "SELECT * FROM candidate_foreign WHERE value BETWEEN '" .$_post['from']. "' AND '".$_post['to']."'"; Link to comment https://forums.phpfreaks.com/topic/43638-search-data-between-two-specific-year/#findComment-211876 Share on other sites More sharing options...
jimjack145 Posted March 21, 2007 Author Share Posted March 21, 2007 thks for your reply. Now i am not getting any error but query is no sending any result. i have created updated table. Please help me to get result. Now code like as below: ---------------------------------------------------------------------------- 1) search.php // search Graduation result Graduation candidate seach<BR> <form name="search1" action="graduation.php" method=post> From : <input type=text size="10" name=from value=""> <BR><BR> To : <Input type=text size="10" name=to value=""><BR><BR> <center><input type="submit" value="Submit"></center> </form> ---------------------------------------------------------------------------- 2) graduation.php <?php $loginname = ""; $password = ""; $database = ""; $con = mysql_connect("localhost", "$loginname", "$password") or die("could not connect"); mysql_select_db("$database"); // your given query $query = "SELECT * FROM candidate_foreign WHERE candidate_foreign.value BETWEEN '" .$_post['from']. "' AND '".$_post['to']."'"; $result = mysql_query ("$query"); echo"<table border=1><TH>Year</TH>"; if(mysql_num_rows($result)){ while ($in = mysql_fetch_array($result)) { echo"<tr>"; echo"<td>". $in['value'] . "<td>"; echo"</tr>"; } } echo "</table>"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/43638-search-data-between-two-specific-year/#findComment-211881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.