7 Replies Latest reply on Sep 2, 2010 11:47 AM by Günter Schenk

    Search Form

    reandre68

      Hi,

       

      I want do develop a search form that can filter 4 different fields. Let me explain:

       

      The search form consists of 4 drop-down menus. The drop-downs comprise a group (a group is 4 categories, Province, City, Accommodation type and price range). I want the user to select his criteria from the 4 menus on the same page (Let's say he chose Province:Gauteng, City:Pretoria, Accommodation type:Hotel, Price Range:R501-R1000), then when he clicks on search, the results page must show the results as per his criteria, i.e Only hotels in the Province Gauteng, the city Pretoria and within a price range of R501-R1000.

       

      Please anybody who can advise me on how to do this, I will be forever grateful.

        • 1. Re: Search Form
          reandre68 Level 1

          Thanks for all the replies. LOL

           

          Anyway I found a bit of code and edited it accordingly. It gives me an error saying: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource but I suspect the problem lies within my query. I just can't figure out what it is. I have FULLTEXT indexing on the four columns.

           

          Please can someone have a look at it and tell me what's wrong?

           

          <?PHP
           
              $term = "'Gauteng', 'Pretoria', 'Hotel', '500.00'";
           
              $sql = "SELECT *, MATCH(province, near_city, accomm_type, norm_price_range) AGAINST('". $term ."') as score FROM travel choice WHERE MATCH (province, near_city, accomm_type, norm_price_range) AGAINST('". $term ."') ORDER BY score DESC";
              $query = mysql_query($sql);
           
               while($result = mysql_fetch_assoc($query)) {
                echo("{$result['near_city']} - {$result['score']}");
              }
               
          ?>
          

           

          This is only a test run of my actual search page, but it's based on my actual DB.

           

          Looking forward to hearing from y'all.

           

          Regards

          • 2. Re: Search Form
            Günter Schenk Level 4

            According to the MySQL documentation "AGAINST takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a literal string". The current value of your variable $term is actually a comma-separated list of values, which are all enclosed in single quotes -- but that´s certainly not the expected "literal string", and hence I assume that this is why you´re getting this error.

             

            What happens when you turn this into a literal string, like:

             

            $term = "Gauteng Pretoria Hotel 500.00";

             

            Cheers,

            Günter

             

            P.S. You may have wondered why you´re not getting many replies in these forum except for mine so far. The forum name "PHP Application Development" as such is somewhat misleading, because in here it´s all about questions which are related to the Dreamweaver extension ADDT, which generates non-standard PHP code and has been discontinued over a year ago. That said, these forums have become pretty quiet by now, and the number of fellow forum participants is much larger in the regular Dreamweaver Application Development forum, which - unlike this one - is made for posting questions about regular PHP stuff.

            • 3. Re: Search Form
              reandre68 Level 1

              Hi,

               

              I will test your suggestion later today and get back to you, thanks.

               

              I have another question, not related to the topic, hope you don't mind answering.

               

              When I upload a specific set of pages to my web server they come out blank??? Strangely enough it is only the pages with a database connection? I have no clue why?

               

              <?php require_once('../Connections/LastMinuteConfirm.php'); ?>
              

               

              That is what I use to connect to my DB

               

              And this is the file you see in the path above-

               

              <?php
              # FileName="Connection_php_mysql.htm"
              # Type="MYSQL"
              # HTTP="true"
              $hostname_LastMinuteConfirm = "";
              $database_LastMinuteConfirm = "";
              $username_LastMinuteConfirm = "";
              $password_LastMinuteConfirm = "";
              $LastMinuteConfirm = mysql_pconnect($hostname_LastMinuteConfirm, $username_LastMinuteConfirm, $password_LastMinuteConfirm) or trigger_error(mysql_error(),E_USER_ERROR); 
              ?>
              

               

              For obvious reasons I have removed my username, etc.

               

              what could be the problem?

               

              Thanks

              • 4. Re: Search Form
                reandre68 Level 1

                I have enabled error report and it says access denied. I am 100% sure that I have the correct access details though.

                • 5. Re: Search Form
                  Günter Schenk Level 4

                  reandre68 wrote:

                   

                  I have enabled error report and it says access denied. I am 100% sure that I have the correct access details though.

                  Are you trying to connect to a remote database, that is, running this script from your localhost while trying to connect to a database which your ISP provides ?

                   

                  Cheers,

                  Günter

                  • 6. Re: Search Form
                    reandre68 Level 1

                    Yes, and thank you for letting me know, I never even thought of it that way. I entered my IP into the remote databse host and now it works. Thanks again.

                     

                    If I upload my page to the server it works as well, but only after I entered the server's shared IP into the same remote host field. Do you know why that happens? I want to access my DB directly if my page is uploaded and not through any shared hosting whatever that means.

                    • 7. Re: Search Form
                      Günter Schenk Level 4

                      reandre68 wrote:

                       

                      If I upload my page to the server it works as well, but only after I entered the server's shared IP into the same remote host field. Do you know why that happens?

                      Your ISP seems to impose more restrictions than another ISP might consider to be important.

                       

                      Cheers,

                      Günter