Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Join Date
    Mar 2008
    Posts
    18

    Unanswered: No serach 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, SpecializationId,SpecializtionArea. in specialization table there are SpecializationArea with same name but with diferent SpecializationId 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.


    Code: ( php )
    //Create Query for Specialization
    if($dropdown == Specialization){
    $query= mysql_query("SELECT QualificationId,SpecializationId FROM specialization WHERE SpecializationArea='$search'");
    while($nt=mysql_fetch_array($query)){
    //echo "" .$nt['QualificationId']. "" .$nt['SpecializationId']. "<BR>";
    $result = "SELECT UserName FROM userdetails WHERE Qualification='$nt[QualificationId]' AND Specialization='$nt[SpecializationId]'" or die (mysql_error());
    $data = mysql_query($result) or die(mysql_error());
    }
    }

    Your help will be appreciated.

    Thanks
    Srushti

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    before you start diving into error mode

    are you certain the SQL you are sending to the db is saying wahtr you think it is
    either echo the SQL or die

    are you certain there is data that matches those criteria. It may be worth while doing your query in say MySQL browser, and then pasting the exact same SQL into the script... so you know what data is going in and you can then check your script handles the data correctly.

  3. #3
    Join Date
    Mar 2008
    Posts
    18
    there is data in the database that matches the criteria. The query works well when i tried executing it in separate file.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what does the SQL you are sending to the server look like.. does it look reasonable.

    Personally I'm not convinced that you can assign the result of a associative array within a string, I'm pretty certain you have to drop out of the string to do that.

    I would expect the second where clause to look like
    WHERE Qualification='".$nt[QualificationId]."' AND Specialization='".$nt[SpecializationId]."'"

  5. #5
    Join Date
    Mar 2008
    Posts
    18
    It doesnt works out with this even. 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.

    $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=mysql_fetch_array($data)){
    //Print it out to page
    echo "" .$info['FullName']. "";
    }// end of while
    }//end of if

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    c\an we see the full script... from the point
    Code:
    if($dropdown == Specialization){
    to the point where are you know think there is a problem
    echo "" .$info['FullName']. "";
    doesn't look right to me echo $info['FullName']; maybe

  7. #7
    Join Date
    Mar 2008
    Posts
    18
    Code:
    /Create Query for Specialization
    if($dropdown == Specialization){
    $query= mysql_query("SELECT QualificationId,SpecializationId FROM specialization WHERE SpecializationArea='$search'");
    while($nt=mysql_fetch_array($query)){
    //echo "" .$nt['QualificationId']. "" .$nt['SpecializationId']. "<BR>";
    $result = "SELECT FullName FROM userdetails WHERE Qualification='$nt[QualificationId]' AND Specialization='$nt[SpecializationId]'" or die (mysql_error()); 
    $data = mysql_query($result) or die(mysql_error()); 
    }
    }
    $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=mysql_fetch_array($data)){
    //Print it out to page 
    echo "<a href=\"searchaccount.php?id={$info['FullName']}\" target=\"_blank\">{$info['FullName']}</a><br/><br/>";
    
    }// end of while
    }//end of if
    else{
    echo "There are no results to be displayed for your search";
    }
    This is the code that works well for other selections in dropdown.
    Last edited by healdem; 03-14-08 at 07:59.

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    First off I find your {} confusing, there is no indentation so the code , the loops, the blocks of code don't really stand out

    at best you will only go through the last loop once, with the last result set from the previous query.

    So im guessing you know if there is anything in $nt['QualificationId']. "" .$nt['SpecializationId']

    I still don't think '$nt[QualificationId]' is correct, have you debugged that SQL to prove what you are sending to the SQL engine is what you think is correct.

    Actually looking at this again shouldn't that be $nt['QualificationId']'.. you need to encapsulate the key/column name in the associateive array with '

    so I'd like to see
    Code:
    $result = "SELECT FullName FROM userdetails
              WHERE Qualification='$nt[QualificationId]'
              AND Specialization='$nt[SpecializationId]'" or die (mysql_error());
    changed to be
    Code:
    $result = "SELECT FullName FROM userdetails
              WHERE Qualification='".$nt['QualificationId']."'
              AND Specialization='".$nt['SpecializationId']."'
     or die (mysql_error());
    incindentally Im not to sure what you expect the or die to do on that statement

    personally If I were you I'd echo / print the number of rows returned for each recordset, immediately after the query has been sent to the SQL engine. that way you know your code is actually finding rows

  9. #9
    Join Date
    Mar 2008
    Posts
    18
    I echoed the QualificationId and SpecializationId. It takes the correct results from the database table specialization.

    echo "" .$nt['QualificationId']. "" .$nt['SpecializationId']. "<BR>";

    But it is not taking values from userdetails table.

  10. #10
    Join Date
    Mar 2008
    Posts
    18
    I tried the changes u told in where clause and also echoed the number of rows. Its showing 0 in number of rows.

  11. #11
    Join Date
    Mar 2008
    Posts
    18
    Should i attach the database and the entire search file

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by agarwalsrushti
    I tried the changes u told in where clause and also echoed the number of rows. Its showing 0 in number of rows.
    so that means its not getting any rows returned, so you SQL is either malformed or there is not data returned or the parameters are banjaxed

    so what was actually sent to the SQL engine.
    echo the SQL before you send it to the SQL engine
    make sure it says what you are expecting it to say.


    if you want to build all the debug data in one hig

    eg
    $Debugdata .= strSQL ."<BR>";
    you can include things like number of rows returned.
    at the end of the script insert die (echo $DebugData);

    try that,
    try replacing the parameters with 2 known good value.. to make sure your script is working correctly, apart from the query.
    if that fails come back with the full script

    if that still doesn't give you a clue, then by all means place the code here. but before you do please make certain you sort out your PHP code blocks, and indentation. it makes it hard to read, it makes it less likely you will get a response. However please don't post the whole script... just the bits that aren't working. So in this case that's your SQL and loops you are using to process the results from the SQL

  13. #13
    Join Date
    Mar 2008
    Posts
    18
    if($dropdown == Specialization)
    {
    $query= mysql_query("SELECT QualificationId,SpecializationId FROM
    specialization WHERE SpecializationArea='$search'");
    while($nt=mysql_fetch_array($query))
    {
    $result = "SELECT FullName FROM userdetails WHERE Qualification='10'
    AND Specialization='31'" or die (mysql_error());
    $data = mysql_query($result) or die(mysql_error());
    }
    }

    I entered the Qualification and Specialization values that are there in my userdetails table. It displayed the result properly. But again when i repaced it with $QualificationId and $SpecializationId it is not diaplaying any result.

  14. #14
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ..are Qualification ID & Specialisation numeric columns, of so then you don't need the quote marks in the where clause
    you may require a semi colon at the end of the SQL statement, in much the same way as PHP lines are terminated by a semi colon, so to are / should SQL lines be terminated by a semi colon

  15. #15
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    strictly speaking this a PHP problem, rather than a MySQL problem, So i'll move the post there

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •