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
$query = "SELECT * FROM candidate_foreign WHERE `Graduation Passing year` BETWEEN" .$_post['from']. "AND '".$_post['to']."'"; $query = "SELECT * FROM candidate_foreign WHERE `Post Graduation Passing year` BETWEEN" .$_post['from']. "AND '".$_post['to']."'";
thks for your reply but getting an error as below: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/graduation.php on line 18 What i do now? and also i want to check data from "value" column... JIMI
$query = "SELECT * FROM candidate_foreign WHERE value BETWEEN<space>" .$_post['from']. "<space> AND<space> '".$_post['to']."'";
now i have following two pages and running without getting any error. But not giving me any result except column name as "year". Please check code of two php file 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"); $query = "SELECT * FROM candidate_foreign WHERE 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); ?>
I think code is ok just prb with query Try this $query = "SELECT * FROM candidate_foreign WHERE value BETWEEN " .$_post['from']. " AND ".$_post['to'];
now getting an error like as below: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/graduation.php on line 18 May be now query is wrong. What u say? JIMI
try to check $_post['from'] and $_post['to'] before use them: echo 'from='.$_post['from']; echo 'to='.$_post['to']; what's the result?
Without value reference from search form i run that graduation.php i got result . what would be the problem in my code? I run below query --------------- <?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 2000 and 2006; $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); ?> -------------- Jimi Just want to assign value of 2000 and 2006 from my search form.
Print these lines at front of graduation.php echo "<pre>"; print_r($_POST); and check that are you getting ur post values ?
thks its work and giving me result now... thank you your urgent help Hai friend i have one more query regarding php. Would u like to help me in that. I have code with that i am paging my data. I just want to sort my data as per every column title. Do u have any idea how would i sort data through column name. I have mulitple column in my table. Hope you would help in this prob too.. Regards, JIMI
yes i think it is the easiest way to check where the problem is in the PHP code or in SQL query try this ...
I just inner join my table with other table and run below query now again its not giving me year. What wrong in query below: "SELECT `first_name`, `last_name`, `address1`, `address2`, `city`, `state`, `current_employer`, `entered_by`, `owner`, `email1` FROM candidate INNER JOIN candidate_foreign ON candidate.candidate_id = candidate_foreign.assoc_id WHERE candidate_foreign.field_name = 'IITYear' AND value >= '" .$_POST['from']. "' AND value <= '".$_POST['to']."'";
Once again i am here for need ur help... I tried mentioned code below at my end: -------- <?php echo 'from='.$_POST['from']; echo 'to='.$_POST['to']; $loginname = ""; $password = ""; $database = ""; $con = mysql_connect("localhost", "$loginname", "$password") or die("could not connect"); mysql_select_db("$database"); $query = "SELECT 'first_name', 'last_name', 'address1', 'address2', 'city', 'state', 'current_employer', 'entered_by', 'owner', 'email1' FROM candidate INNER JOIN candidate_foreign ON candidate.candidate_id = candidate_foreign.assoc_id WHERE candidate_foreign.field_name = 'IITYear' AND value >= '" .$_POST['from']. "' AND '".$_POST['to']."'"; $result = mysql_query ("$query"); echo"<table border=1><TH>First Name</TH><TH>Address</TH><TH>Last Name</TH><TH>City</TH><TH>State</TH><TH>Email</TH>"; while ($in = mysql_fetch_array($result)) { echo"<tr>"; echo"<td>". $in['first_name'] . "<td>"; echo"<td>". $in['address1'] . "<td>"; echo"<td>". $in['last_name'] . "<td>"; echo"</tr>"; } echo "</table>"; mysql_close($con); ?> ------- When i run at my end with help of search.php . I have been not getting any error. but also i not getting any value from table too. I am getting error as below: ---------- from=2006to=2009 First Name Address Last Name City State Email first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name first_name address1 last_name -------------- Please help as u did last day. JIMI