Jump to content

Search data between two specific year?


jimjack145

Recommended Posts

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

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);

 

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.