Search data between two specific year?

Discussion in 'PHP' started by jimjack145, Mar 21, 2007.

  1. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #21
    $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']."'";
    ---------------------------

    Now write

    $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 value <= ".$_POST['to'];

    Or Remove ' from list of the feilds which have you mention after SELECT
     
    jitesh, Mar 22, 2007 IP
  2. jimjack145

    jimjack145 Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #22
    <?PHP

    $loginname = '';

    $password = '';

    $database = '';

    $con = mysql_connect("localhost", "$loginname", "$password") or die("could not connect");
    mysql_select_db("$database");

    $query = "SELECT * from candidate, candidate_foreign 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 "You are seaching between year '" .$_POST['from']. "' to '" .$_POST['to']. "'";

    echo "<TABLE BORDER=1><TH>First Name</TH><TH>Last Name</TH><TH>Year</TH>";


    while ($in = mysql_fetch_array($result))
    {
    echo "<TR>";
    echo "<TD>" . $in[first_name] . "</TD>";
    echo "<TD>" . $in[last_name] ."</TD>";
    echo "<TD>" . $in[value] ."</TD>";
    echo "</TR>";
    }

    echo "</TABLE>";

    mysql_close($con);

    ?>

    I want to retrieve year of passing from candidate_foreign table but after run this code i got error as below:

    mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/datalist_year.php on line 21

    I tried if (mysql_num_rows($result) before while that time gave and error for mysql_fetch_rows()..

    How could i get data from both tables?
    Is there any other code except loop i have to use to retrieve data into php formate.

    hope you reply soon

    Regards,
    Jimi
     
    jimjack145, Mar 22, 2007 IP
  3. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #23
    $query = "SELECT * 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'];
     
    jitesh, Mar 22, 2007 IP