No search result is displayed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsrushti
    New Member
    • Feb 2008
    • 63

    No search result is displayed

    Hi,
    Im just stuck up with a small query. In my database ive a table called specialization which is dependent on qualification. In specialization i ve 3 fields: QualificationId , SpecializationI d,Specializtion Area. in specialization table there are SpecializationA rea with same name but with diferent SpecializationI d and QualificationId . Now when i enter search page and select to search based on specialization then it doesnt displays the results for search. In the userdetails table specialization and qualification are stored with thier id values.
    Ive used the query below. Is the query correct?


    [code=php]
    //Create Query for Specialization
    if($dropdown == Specialization) {
    $query= mysql_query("SE LECT QualificationId ,Specialization Id FROM specialization WHERE SpecializationA rea='$search'") ;
    while($nt=mysql _fetch_array($q uery)){
    //echo "" .$nt['QualificationI d']. "" .$nt['Specialization Id']. "<BR>";
    $result = "SELECT UserName FROM userdetails WHERE Qualification=' $nt[QualificationId]' AND Specialization= '$nt[SpecializationI d]'" or die (mysql_error()) ;
    $data = mysql_query($re sult) or die(mysql_error ());
    }
    }
    [/code]

    Your help will be appreciated.

    Thanks
    Srushti
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    First ensure that data exists in database as per your search conditions.

    It is always better to use LIKE instead of using = for search operation.

    Comment

    • agarwalsrushti
      New Member
      • Feb 2008
      • 63

      #3
      Originally posted by debasisdas
      First ensure that data exists in database as per your search conditions.

      It is always better to use LIKE instead of using = for search operation.
      Thanks. There is data in the userdetails table as per the condition.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        Your query looks fine it is the php code that looks wrong.
        Some debugging statements would help!
        Anyway[PHP]if($dropdown == Specialization) {[/PHP] Here php will treat Specialization as a constant.
        If you had error_reporting () switched on as recommended in this forum
        then this would have flashed a warning
        What is Specialization meant to be, a string?
        [PHP]if($dropdown == 'Specialization '){[/PHP]

        Comment

        • agarwalsrushti
          New Member
          • Feb 2008
          • 63

          #5
          Here Specialization is a constant. Its the value that i ve assigned to it in drop down. The other constants work fine and displays the result. Its not going in this while loop even if matches are there. I dont think theres a problem with this loop coz it works well for other search criterias and displays the results.

          [code=php]
          $resultnum = mysql_num_rows( $data); // Just print $resultnum if you want to show how many results returned
          if($resultnum>0 ) { // Echos out matches if anything was found
          while($info=mys ql_fetch_array( $data)){
          //Print it out to page
          echo "" .$info['FullName']. "";
          }// end of while
          }//end of if
          [/code]

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            I am suprised this works [PHP]$result = "SELECT UserName FROM userdetails WHERE Qualification=' $nt[QualificationId]'
            AND Specialization= '$nt[SpecializationI d]'" or die (mysql_error()) ; [/PHP] Arrays in query strings always produce an error for me and require curly braces [PHP]$result = "SELECT UserName FROM userdetails WHERE Qualification=' {$nt[QualificationId]}'
            AND Specialization= '{$nt[SpecializationI d]}'" or die (mysql_error()) ; [/PHP] Don't understand what you mean
            Here Specialization is a constant. Its the value that i ve assigned to it in drop down

            Comment

            Working...