1 2 Previous Next 47 Replies Latest reply: Mar 29, 2013 1:40 AM by IVYY RSS

    search engine powered by data base in dw cs6?

    IVYY Community Member

      Hi, I am new to dreamweaver cs6. I need to create a website for my school project.

       

      My idea is to create a search engine that is powered by my own data base.

       

      When users type in the books' titles, it will provide them with search results and maybe information from my database.

       

      May I know how should i go about doing it?

       

      Please provide detailed steps as I am really very new to dw cs6.

       

      Should I use Mysql or microsoft access to create a database?

       

      Thanks!

        • 1. Re: search engine powered by data base in dw cs6?
          MurraySummers CommunityMVP

          Should I use Mysql or microsoft access to create a database?

           

          It would depend on the Operating system running on the server that is hosting the pages and the database. If it's Windows then you may be stuck with Access (not particularly good news). If it's Unix/Linux then you can use MySQL and PHP (that's good news). You need to ask the host for the pages you will create.

           

          So - that's step one. You have a long distance to go. How skilled are you with HTML/CSS and PHP or ASP or ASP.NET?

          • 2. Re: search engine powered by data base in dw cs6?
            IVYY Community Member

            Hi,

             

            Thanks for your help.

             

            I just downloaded Mysql and created my trial database.

             

            And i also created a php file but I cant seem to set up the site's testing server.

             

            I am using iis 8 windows web server. I have set up at a local file on my desktop, a remote file which is in my c drive and connects to the wwwroot file by a virtual directory. But I seem unable to get the testing server part.

            • 3. Re: search engine powered by data base in dw cs6?
              MurraySummers CommunityMVP

              Where will you host this stuff?  You can't host it locally. And IIS can't execute PHP - you would need Apache to do that.

               

              Google "WAMP" to see how to get that installed on your system.

               

              Are you developing this just for a demonstration on your local box, or for something that will serve the whole class and persist at your school as a tool for others to use?

              • 4. Re: search engine powered by data base in dw cs6?
                IVYY Community Member

                Hi,

                 

                Thanks for your help again!

                 

                The thing is that I set up my iis 8 web server, run command prompt to get my ipv4 then i can tell my teacher or peers to access the webpage on their smartphones by entering the ipv4 follows by the webpage title.

                 

                I can set up my test server now on dreamweaver but it seems that i cant setup a connection successfully to mysql. i always get the http 405 error message.

                 

                I will google WAMP and try it.

                • 5. Re: search engine powered by data base in dw cs6?
                  MurraySummers CommunityMVP

                  So you are planning on hosting this yourself?  I don't think that's a good idea.

                  • 6. Re: search engine powered by data base in dw cs6?
                    IVYY Community Member

                    Will there be another alternative?

                    • 7. Re: search engine powered by data base in dw cs6?
                      MurraySummers CommunityMVP

                      Have the page hosted at your school on the servers there - it's the right way to do this.

                      • 8. Re: search engine powered by data base in dw cs6?
                        IVYY Community Member

                        Oh i forgot to mention that my teacher always brought along his own router so that we can connect to it by wifi, drop our webpages in our wwwroot folders, find out the ipv4 address and then connect to the webpages in our smartphones by entering the ipv4 followed by the title of the webpage.

                         

                        So I would like to ask how do I proceed from here. Do I use Mysql workbench or phpadmin to create the database?

                         

                        And do switch to wamp to create the local host instead of iis?

                         

                        Thank you!

                        • 9. Re: search engine powered by data base in dw cs6?
                          IVYY Community Member

                          Hi,

                           

                          I managed to install waap and edited my database in myphpadmin.

                           

                          I also successfully managed to connect my database to dreamweaver after giving up IIS and using waap.

                           

                          I would like to ask how should I proceed in enabling my search textfield to be database smart.

                           

                          In layman term, when i key certain keywords, it will return another webpage to show the relevant information from my database.

                           

                          Is what I say possible?

                          • 10. Re: search engine powered by data base in dw cs6?
                            MurraySummers CommunityMVP

                            Is what I say possible?

                             

                            Certainly. But you would need to know how to build the PHP page to do that. Do you know any PHP?

                            • 11. Re: search engine powered by data base in dw cs6?
                              IVYY Community Member

                              Hi,

                               

                              I guess my knowledge on php is limited.

                               

                              But I just created a blank php page with a search text field and a search submit.

                               

                              May I know what should I do to make it return search results that I like?

                               

                              In layman terms, if I type in twilight in the search bar and submit, it will trigger the database and return search results like title, author, publisher, ISBN, book price, availability stock from the database in another webpage (do i use html or php then?)

                               

                              I guess you have been helpful in directing me to come this far. I would appreciate it if you could provide me with more details on proceeding.

                               

                              Thanks in advance!

                              • 12. Re: search engine powered by data base in dw cs6?
                                MurraySummers CommunityMVP

                                Here's the basic idea (this would all be done in PHP):

                                 

                                1. Take the submitted data and do a SQL select on the database using that data.

                                2. Count the number of records found - if the count is zero, then nothing was found. Ouput that to the screen.

                                3. If there are records found then output each record to the screen using a do loop.

                                 

                                So - let's assume your search form contains a field called "keyword", and you want to find all records that contain that keyword in the title. In a very sketchy fashion, you would have code built around these actions -

                                 

                                $keyword = $_POST['keyword']; /* this loads a variable with the submitted keyword */

                                ...

                                $query_rsRecords = "SELECT * FROM table WHERE title LIKE %$keyword% ORDER BY author /* this is the way to search the database table="table" and field="title" */

                                $rsRecords = mysql_query($query_rsRecords, $databaseName) or die(mysql_error()); /* this actually performs the search */

                                $row_rsRecords = mysql_fetch_assoc($query_rsRecords); /* this returns the first record in the recordset */

                                $totalRows_rsRecords = mysql_num_rows($rsRecords); /* this counts how many rows are returned by the search */

                                 

                                DW will do much of this for you - open the page, add a database and connection to it, then add a recordset. You should read through the tutorials on the Adobe site about how to build a dynamic page to get the full story.

                                • 13. Re: search engine powered by data base in dw cs6?
                                  IVYY Community Member

                                  Hi,

                                   

                                  Thanks for your reply! I really appreciateit.

                                   

                                  I have successfully created dynamic registration, user log in and log out pages that interact with my database. Now it is the search system that got me stuck.

                                   

                                  I followed the adobe tutorial to create a dynamic table but it is not working for me.

                                   

                                  Here is what I did.

                                   

                                  I created a form, then I created another form textfield and a submit button inside it. What should I put for action and method for this form? (I put none for action tab and get for method tab)

                                   

                                  Next, I started to create a recordset behaviour, connecting to my database (books), selecting a table (books). I filtered title (which is one of the column in my database table) to be equal to URL parameter and I put "Search3" (which is the ID of the earlier search textfield) in the box next to the URL parameter.

                                   

                                  Then I inserted a dynamic table choosing the recordset that i have earlier created.

                                   

                                  But when I test my site on chrome, nothing changes. When i typed a specific title in the search textfield and pressed submit, the dynamic table did not reflect any results from my database.

                                   

                                  Did I do something wrong? May you give advice to me. Thanks!

                                  • 14. Re: search engine powered by data base in dw cs6?
                                    IVYY Community Member

                                    Hi,

                                     

                                    I managed to do it if i put the search bar on the search page and the record set and dynamic table on the result page.

                                     

                                    I want to ask is it possible to put search bar, record set and dynamic table in one page. How ould i go about changing the action tab and method tab of the form field.

                                     

                                    Next I would like to ask, is it possible to display a specific picture (like an image of the book cover) beside my search result in the dynamic table? It is like if i search harry potter in the search textfield, it will come out with the returned information like title, author, publisher, ISBN, price from the database table, but I would like the harry potter book cover beside the returned information.

                                     

                                    I think I have learned alot about dreamweaver, php, mysql as I started from scratch. It seems like I have a long way to go.

                                    • 15. Re: search engine powered by data base in dw cs6?
                                      MurraySummers CommunityMVP

                                      I want to ask is it possible to put search bar, record set and dynamic table in one page. How ould i go about changing the action tab and method tab of the form field.

                                       

                                      Yes, you can do this. The action attribute of the form tag would be set to submit to the page itself -

                                       

                                      <form action="<?php echo $_SERVER['PHP_SELF']; ?>"

                                       

                                      Then you'd have to protect the various blocks of PHP code at the top from running until you want them to. So, for example, the block of code that pulls the results recordset would need to be in a conditional like -

                                       

                                      <?php if(array_key_exists('the_name_of_your_submit_button',$_POST)) { ?>

                                      /* all the recordset code */

                                      <?php } ?>

                                       

                                      And the code that loops through the recordset to display the results would need to be in a conditional like -

                                       

                                      <?php if(isset($totalRows_rsResults) && $totalRows_rsResults > 0) { ?>

                                      /* the loop code */

                                      <?php } ?>

                                       

                                      So, when the page first loads, neither of those conditionals evaluate true, so neither of them apply. The first conditional will evaluate true after the form has submitted (to the same page), and the second will evaluate true when any results are returned.

                                       

                                      Also, as long as you have the cover image filename as part of each record, you can easily add it to the results table by placing a dynamic image in your results loop -

                                       

                                      <img src="path_to_cover_image_folder/<?php echo $row_rsResults['coverImage']; ?>">

                                      • 16. Re: search engine powered by data base in dw cs6?
                                        IVYY Community Member

                                        Hi,

                                         

                                        Thanks for your advice! It works wonder.

                                         

                                        I managed to get the dynamic pictures as part of my results.

                                         

                                        I would like to ask how do I make my search textfield more smart.

                                         

                                        For example, I would want to search by author OR publisher OR price OR ISBN etc. Do i create a separate recordset for each of the search terms OR do i use the same recordset? Will I be able to use the same dynamic table?

                                         

                                        And lastly, I would like to have a link from my dynamic table results. For example, users can click on the title which is in the results of the dynamic table to go into another page that contains even more details.

                                         

                                        Thank you, mentor!

                                        • 17. Re: search engine powered by data base in dw cs6?
                                          MurraySummers CommunityMVP

                                          Show us the code that you have now. It'll be easier to show you how to do what you want to do in the context of what you already have.

                                          • 18. Re: search engine powered by data base in dw cs6?
                                            IVYY Community Member

                                            Hi,

                                             

                                            Below is the code of my main page:

                                             

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

                                            <?php

                                            //initialize the session

                                            if (!isset($_SESSION)) {

                                              session_start();

                                            }

                                             

                                             

                                            // ** Logout the current user. **

                                            $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";

                                            if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){

                                              $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);

                                            }

                                             

                                             

                                            if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){

                                              //to fully log out a visitor we need to clear the session varialbles

                                              $_SESSION['MM_Username'] = NULL;

                                              $_SESSION['MM_UserGroup'] = NULL;

                                              $_SESSION['PrevUrl'] = NULL;

                                              unset($_SESSION['MM_Username']);

                                              unset($_SESSION['MM_UserGroup']);

                                              unset($_SESSION['PrevUrl']);

                                             

                                              $logoutGoTo = "My Kino Log In Page.php";

                                              if ($logoutGoTo) {

                                                header("Location: $logoutGoTo");

                                                exit;

                                              }

                                            }

                                            ?>

                                            <?php

                                            if (!function_exists("GetSQLValueString")) {

                                            function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                                            {

                                              if (PHP_VERSION < 6) {

                                                $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                                              }

                                             

                                             

                                              $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                                             

                                             

                                              switch ($theType) {

                                                case "text":

                                                  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                  break;   

                                                case "long":

                                                case "int":

                                                  $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                                  break;

                                                case "double":

                                                  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                                  break;

                                                case "date":

                                                  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                  break;

                                                case "defined":

                                                  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                                  break;

                                              }

                                              return $theValue;

                                            }

                                            }

                                             

                                             

                                            $colname_RsHp = "-1";

                                            if (isset($_SESSION['MM_Username'])) {

                                              $colname_RsHp = $_SESSION['MM_Username'];

                                            }

                                            mysql_select_db($database_Users, $Users);

                                            $query_RsHp = sprintf("SELECT * FROM users WHERE Email = %s", GetSQLValueString($colname_RsHp, "text"));

                                            $RsHp = mysql_query($query_RsHp, $Users) or die(mysql_error());

                                            $row_RsHp = mysql_fetch_assoc($RsHp);

                                            $totalRows_RsHp = mysql_num_rows($RsHp);

                                             

                                             

                                            $colname_RsHP = "-1";

                                            if (isset($_SESSION['User_Var_2012'])) {

                                              $colname_RsHP = $_SESSION['User_Var_2012'];

                                            }

                                            mysql_select_db($database_Users, $Users);

                                            $query_RsHP = sprintf("SELECT * FROM users WHERE Email = %s", GetSQLValueString($colname_RsHP, "text"));

                                            $RsHP = mysql_query($query_RsHP, $Users) or die(mysql_error());

                                            $row_RsHP = mysql_fetch_assoc($RsHP);

                                            ?>

                                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                                            <html xmlns="http://www.w3.org/1999/xhtml">

                                            <head>

                                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                                            <title>My Kino Home Page</title>

                                            <style type="text/css">

                                            .search {

                                                      width: 300px;

                                                      alignment-adjust: central;

                                                      height: 35px;

                                                      font-size: 30px;

                                            }

                                            .submit {

                                                      height: 40px;

                                                      width: 80px;

                                            }

                                            </style>

                                            </head>

                                             

                                             

                                            <body>

                                            <table width="100%" border="1">

                                              <tr>

                                                <td> <div align="center">My Kino Home Page </div></td>

                                              </tr>

                                              <tr>

                                                <td> Welcome: <?php echo $row_RsHp['Nick Name']; ?></td>

                                              </tr>

                                              <tr>

                                                <td><div align="right"><a href="<?php echo $logoutAction ?>">Logout</a></div></td>

                                              </tr>

                                            </table>

                                            <p> </p>

                                            <form id="form1" name="form1" method="get" action="My Kino Result Page.php">

                                              <p> </p>

                                              <table width="400" height="60" border="1" align="center">

                                                <tr>

                                                  <td width="307"><input name="Search" type="text" class="search" id="Search" /></td>

                                                  <td width="77"><input name="Submit" type="submit" class="submit" id="Submit" value="Submit" /></td>

                                                </tr>

                                              </table>

                                              <p> </p>

                                            </form>

                                            <p> </p>

                                             

                                             

                                            </body>

                                            </html>

                                            <?php

                                            mysql_free_result($RsHp);

                                            ?>

                                            • 19. Re: search engine powered by data base in dw cs6?
                                              IVYY Community Member

                                              This is the code for my result page:

                                               

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

                                              <?php

                                              if (!function_exists("GetSQLValueString")) {

                                              function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                                              {

                                                if (PHP_VERSION < 6) {

                                                  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                                                }

                                               

                                               

                                                $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                                               

                                               

                                                switch ($theType) {

                                                  case "text":

                                                    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                    break;   

                                                  case "long":

                                                  case "int":

                                                    $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                                    break;

                                                  case "double":

                                                    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                                    break;

                                                  case "date":

                                                    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                    break;

                                                  case "defined":

                                                    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                                    break;

                                                }

                                                return $theValue;

                                              }

                                              }

                                               

                                               

                                              $colname_Rssearch = "-1";

                                              if (isset($_GET['Search'])) {

                                                $colname_Rssearch = $_GET['Search'];

                                              }

                                              mysql_select_db($database_books, $books);

                                              $query_Rssearch = sprintf("SELECT Title, Author, Publisher, Binding, ISBN, `Price (S$)`, `Availability Status`, `Shelf Location`, Images FROM books WHERE Title = %s ORDER BY Title ASC", GetSQLValueString($colname_Rssearch, "text"));

                                              $Rssearch = mysql_query($query_Rssearch, $books) or die(mysql_error());

                                              $row_Rssearch = mysql_fetch_assoc($Rssearch);

                                              $totalRows_Rssearch = mysql_num_rows($Rssearch);

                                              ?>

                                              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                                              <html xmlns="http://www.w3.org/1999/xhtml">

                                              <head>

                                              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                                              <title>Untitled Document</title>

                                              </head>

                                               

                                               

                                              <body>

                                              <table height="285" border="1">

                                                <tr>

                                                  <td>Images</td>

                                                  <td height="48">Title</td>

                                                  <td>Author</td>

                                                  <td>Publisher</td>

                                                  <td>ISBN</td>

                                                  <td>Price (S$)</td>

                                                </tr>

                                                <?php do { ?>

                                                  <tr>

                                                    <td><img src="Images/<?php echo $row_Rssearch['Images']; ?>" width="193" height="300" /></td>

                                                    <td><?php echo $row_Rssearch['Title']; ?></td>

                                                    <td><?php echo $row_Rssearch['Author']; ?></td>

                                                    <td><?php echo $row_Rssearch['Publisher']; ?></td>

                                                    <td><?php echo $row_Rssearch['ISBN']; ?></td>

                                                    <td><?php echo $row_Rssearch['Price (S$)']; ?></td>

                                                  </tr>

                                                  <?php } while ($row_Rssearch = mysql_fetch_assoc($Rssearch)); ?>

                                              </table>

                                              <p> </p>

                                              <p><a href="My Kino Main Page.php">Main page</a></p>

                                               

                                               

                                              </body>

                                              </html>

                                              <?php

                                              mysql_free_result($Rssearch);

                                              ?>

                                              • 20. Re: search engine powered by data base in dw cs6?
                                                MurraySummers CommunityMVP

                                                What you are describing is called a "Master, Detail page" - see INSERT > Data Objects > Master Detail Page Set. It's very straightforward.

                                                 

                                                To search by one or more of the items you describe, you would need for your search form to have a separate field for each such item (title, author, ISBN, etc.). There are multiple ways to handle this kind of search, but the easy way for you to do it would be to pull a recordset for each search term. To get really fancy, you could add the use of the SQL wildcard "%" with the SQL command "LIKE", but I'll leave this to the reader.

                                                 

                                                Finally, your output would need to be adjusted to show each recordset in turn.

                                                 

                                                Can you follow that?

                                                • 21. Re: search engine powered by data base in dw cs6?
                                                  IVYY Community Member

                                                  Hi,

                                                   

                                                  I can follow and have successfully created the master detail page. Thanks!

                                                   

                                                  But I could not follow your 2nd and 3rd points. To search more than one items, I created more than one form objects in the same form in my main page. But do i need to create a separate recordset for each search term in the results page?

                                                   

                                                  I also face problems when I try to create search by price. For example: I have price select options like 10-15, 15-20, 20-25. If I select 10-15, how do I make my result to show only books that cost between $10 and $15.

                                                   

                                                  Lastly, is it possible to create a specific link in my detail page to either pop up a specific image or link to another page that shows the image?

                                                   

                                                  For example, when i clicked on one of the detail record set (shelf locations) in the detailed page, it will either pop up my store map or link to another page that shows the map image.

                                                   

                                                  Thank you!

                                                  • 22. Re: search engine powered by data base in dw cs6?
                                                    MurraySummers CommunityMVP

                                                    To search more than one items, I created more than one form objects in the same form in my main page. But do i need to create a separate recordset for each search term in the results page?

                                                     

                                                    That would be the easiest way at this point since separate recordsets require simpler logic in the MySQL queries. A better way would be to successively build the final SQL query based on the data submitted, e.g.,

                                                     

                                                    $query = "SELECT Title, Author, Publisher, Binding, ISBN, `Price (S$)`, `Availability Status`, `Shelf Location`, Images FROM books WHERE ";

                                                    if !empty($_POST['title']) { $query .= "Title LIKE %" . $_POST['title'] . "% "; }

                                                    if !empty($_POST['author']) { if !empty ($_POST['title']) { $query .= "AND "; } $query .= "Author LIKE %" . $_POST['author'] . "% "; }

                                                    if !empty($_POST['publisher']) { if !empty ($_POST['title'] || !empty ($_POST['author')) { $query .= "AND "; } $query .= "Publisher LIKE %" . $_POST['publisher'] . "% "; }

                                                    etc.

                                                    • 23. Re: search engine powered by data base in dw cs6?
                                                      MurraySummers CommunityMVP

                                                      To search for price, you would need to have a consistent increment in your price selections (you show $5). So in that case you would have to modify the SQL statement's WHERE clause (manually) to something like -

                                                       

                                                      WHERE `Price (S$)` >= $p1 AND `Price (S$)` <= $p2

                                                       

                                                      ($p1 is the selected value and $p2 is the selected value plus the constant increment)

                                                       

                                                      Lastly, is it possible to create a specific link in my detail page to either pop up a specific image or link to another page that shows the image?

                                                       

                                                      Yes. I'll leave that as an exercise for the reader. By now, you should certainly be able to manage it.

                                                      • 24. Re: search engine powered by data base in dw cs6?
                                                        IVYY Community Member

                                                        Hi,

                                                         

                                                        I got it for the search on price. Thanks for the help!

                                                         

                                                        I still have problem with the 2nd point. Currently I have 2 form objects. One is the search textfield while the other is the select list.

                                                         

                                                        What if the same form object (which is the One and Only search textfield)  is used to search Title, Author or Publisher etc? For the select list, it is used to select a price range.

                                                         

                                                        I would have two form objects. The first form object can search three types of key terms in my database while the 2nd form object only searches the price.

                                                         

                                                        Do I use the same Recordset in the advanced form at my result page?

                                                         

                                                        Would I be able to display the results of both form objects in the same master list?

                                                         

                                                        Thank you!

                                                        • 25. Re: search engine powered by data base in dw cs6?
                                                          IVYY Community Member

                                                          Hi,

                                                           

                                                          I managed to figure out to search different terms in my search text field.

                                                           

                                                          this is from my sql of my Recordset in advanced form.

                                                          SELECT *

                                                          FROM books

                                                          WHERE books.Title like %colname% OR books.Author like %colname% OR books.Publisher like %colname% OR books.ISBN like %colname%

                                                          ORDER BY books.Title

                                                           

                                                          My current problem is still on how to show results from two form objects ( search text field) and (price select list) in the same master list.

                                                           

                                                          Thank you!

                                                          • 26. Re: search engine powered by data base in dw cs6?
                                                            MurraySummers CommunityMVP

                                                            <h2>Header Describing 1st recordset's Data</h2>

                                                            <?php do { ?>

                                                            <p>record_data_here_from_recordset1</p>

                                                            <?php } while (blahblah); ?>

                                                            <h2>Header Describing 2nd recordset's Data</h2>

                                                            <?php do { ?>

                                                            <p>record_data_here_from_recordset2</p>

                                                            <?php } while (blahblah); ?>

                                                            • 27. Re: search engine powered by data base in dw cs6?
                                                              IVYY Community Member

                                                              Hi Sir,

                                                               

                                                              Currently when i type nothing in the search bar and press submit, it reveals all my search results. Is it something got to do with mysql wildcard % and like?

                                                               

                                                              Moreover, I would like to ask how do I create an error result page which would tell the users that what they search are unavailable and ask them to try again?

                                                               

                                                              Thanks!

                                                              • 28. Re: search engine powered by data base in dw cs6?
                                                                MurraySummers CommunityMVP

                                                                Currently when i type nothing in the search bar and press submit, it reveals all my search results. Is it something got to do with mysql wildcard % and like?

                                                                Yes. With nothing in any of the search fields, the logic will return all records in the database. You will have to trap that situation in your code and return a message that a search requires one or both fields to be completed. You could, for example, try something like this -

                                                                 

                                                                if (!isset($_POST['Title']) && !isset($_POST['Author']) && !isset(...)) {

                                                                $error ="You must complete a field to perform a search!";

                                                                } else {

                                                                $query = "SELECT Title, Author, Publisher, Binding, ISBN, `Price (S$)`, `Availability Status`, `Shelf Location`, Images FROM books WHERE ";

                                                                etc....

                                                                }

                                                                 

                                                                and then on the page right before the do loop, put -

                                                                 

                                                                if(isset($error)) { ?>

                                                                <p style="color:red;"><?php echo $error; ?></p>

                                                                <?php } else { ?>

                                                                 

                                                                and then after the output loops, close the bracket -

                                                                 

                                                                <?php } ?>

                                                                • 29. Re: search engine powered by data base in dw cs6?
                                                                  IVYY Community Member

                                                                  Hi Sir,

                                                                   

                                                                  May I know where to insert the new lines? I am very lost in this part. Here is my code:

                                                                   

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

                                                                  <?php

                                                                  if (!function_exists("GetSQLValueString")) {

                                                                  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                                                                  {

                                                                    if (PHP_VERSION < 6) {

                                                                      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                                                                    }

                                                                   

                                                                   

                                                                    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                                                                   

                                                                   

                                                                    switch ($theType) {

                                                                      case "text":

                                                                        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                                        break;   

                                                                      case "long":

                                                                      case "int":

                                                                        $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                                                        break;

                                                                      case "double":

                                                                        $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                                                        break;

                                                                      case "date":

                                                                        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                                        break;

                                                                      case "defined":

                                                                        $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                                                        break;

                                                                    }

                                                                    return $theValue;

                                                                  }

                                                                  }

                                                                   

                                                                   

                                                                  $currentPage = $_SERVER["PHP_SELF"];

                                                                   

                                                                   

                                                                  $maxRows_Rssearch = 10;

                                                                  $pageNum_Rssearch = 0;

                                                                  if (isset($_GET['pageNum_Rssearch'])) {

                                                                    $pageNum_Rssearch = $_GET['pageNum_Rssearch'];

                                                                  }

                                                                  $startRow_Rssearch = $pageNum_Rssearch * $maxRows_Rssearch;

                                                                   

                                                                   

                                                                  $colname_Rssearch = "-100000000000000000000000000";

                                                                  if (isset($_GET['Search'])) {

                                                                    $colname_Rssearch = $_GET['Search'];

                                                                  }

                                                                  mysql_select_db($database_books, $books);

                                                                  $query_Rssearch = sprintf("SELECT * FROM books WHERE books.Title like %s OR books.Author like %s OR books.Publisher like %s OR books.ISBN like %s", GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"));

                                                                  $query_limit_Rssearch = sprintf("%s LIMIT %d, %d", $query_Rssearch, $startRow_Rssearch, $maxRows_Rssearch);

                                                                  $Rssearch = mysql_query($query_limit_Rssearch, $books) or die(mysql_error());

                                                                  $row_Rssearch = mysql_fetch_assoc($Rssearch);

                                                                   

                                                                   

                                                                  if (isset($_GET['totalRows_Rssearch'])) {

                                                                    $totalRows_Rssearch = $_GET['totalRows_Rssearch'];

                                                                  } else {

                                                                    $all_Rssearch = mysql_query($query_Rssearch);

                                                                    $totalRows_Rssearch = mysql_num_rows($all_Rssearch);

                                                                  }

                                                                  $totalPages_Rssearch = ceil($totalRows_Rssearch/$maxRows_Rssearch)-1;

                                                                   

                                                                   

                                                                  $queryString_Rssearch = "";

                                                                  if (!empty($_SERVER['QUERY_STRING'])) {

                                                                    $params = explode("&", $_SERVER['QUERY_STRING']);

                                                                    $newParams = array();

                                                                    foreach ($params as $param) {

                                                                      if (stristr($param, "pageNum_Rssearch") == false &&

                                                                          stristr($param, "totalRows_Rssearch") == false) {

                                                                        array_push($newParams, $param);

                                                                      }

                                                                    }

                                                                    if (count($newParams) != 0) {

                                                                      $queryString_Rssearch = "&" . htmlentities(implode("&", $newParams));

                                                                    }

                                                                  }

                                                                  $queryString_Rssearch = sprintf("&totalRows_Rssearch=%d%s", $totalRows_Rssearch, $queryString_Rssearch);

                                                                  ?>

                                                                   

                                                                   

                                                                   

                                                                   

                                                                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                                                                  <html xmlns="http://www.w3.org/1999/xhtml">

                                                                  <head>

                                                                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                                                                  <title>My Kino Result Page</title>

                                                                  </head>

                                                                   

                                                                   

                                                                  <body>

                                                                  <table border="1" align="center">

                                                                    <tr>

                                                                      <td>Images</td>

                                                                      <td>Title</td>

                                                                      <td>Author</td>

                                                                      <td>Publisher</td>

                                                                      <td>ISBN</td>

                                                                      <td>Price (S$)</td>

                                                                    </tr>

                                                                    <?php do { ?>

                                                                      <tr>

                                                                        <td><img src="Images/<?php echo $row_Rssearch['Images']; ?>" width="193" height="300" /> </td>

                                                                        <td><p> </p>

                                                                          <p><a href="My Kino Detailed Page.php?recordID=<?php echo $row_Rssearch['Title']; ?>"><?php echo $row_Rssearch['Title']; ?>  </a></p>

                                                                        <p> </p></td>

                                                                        <td><p> </p>

                                                                          <p><?php echo $row_Rssearch['Author']; ?> </p>

                                                                        <p> </p></td>

                                                                        <td><p> </p>

                                                                          <p><?php echo $row_Rssearch['Publisher']; ?>  </p>

                                                                        <p> </p></td>

                                                                        <td><p> </p>

                                                                          <p><?php echo $row_Rssearch['ISBN']; ?>  </p>

                                                                        <p> </p></td>

                                                                        <td><p> </p>

                                                                          <p><?php echo $row_Rssearch['Price (S$)']; ?></p>

                                                                        <p> </p>        <p> </p></td>

                                                                      </tr>

                                                                      <?php } while ($row_Rssearch = mysql_fetch_assoc($Rssearch)); ?>

                                                                  </table>

                                                                  <br />

                                                                  <table border="0">

                                                                    <tr>

                                                                      <td><?php if ($pageNum_Rssearch > 0) { // Show if not first page ?>

                                                                          <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, 0, $queryString_Rssearch); ?>">First</a>

                                                                          <?php } // Show if not first page ?></td>

                                                                      <td><?php if ($pageNum_Rssearch > 0) { // Show if not first page ?>

                                                                          <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, max(0, $pageNum_Rssearch - 1), $queryString_Rssearch); ?>">Previous</a>

                                                                          <?php } // Show if not first page ?></td>

                                                                      <td><?php if ($pageNum_Rssearch < $totalPages_Rssearch) { // Show if not last page ?>

                                                                          <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, min($totalPages_Rssearch, $pageNum_Rssearch + 1), $queryString_Rssearch); ?>">Next</a>

                                                                          <?php } // Show if not last page ?></td>

                                                                      <td><?php if ($pageNum_Rssearch < $totalPages_Rssearch) { // Show if not last page ?>

                                                                          <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, $totalPages_Rssearch, $queryString_Rssearch); ?>">Last</a>

                                                                          <?php } // Show if not last page ?></td>

                                                                    </tr>

                                                                  </table>

                                                                  <p>Records <?php echo ($startRow_Rssearch + 1) ?> to <?php echo min($startRow_Rssearch + $maxRows_Rssearch, $totalRows_Rssearch) ?> of <?php echo $totalRows_Rssearch ?>

                                                                  </p>

                                                                  <p><a href="My Kino Main Page.php">Main page</a></p>

                                                                  </body>

                                                                  </html>

                                                                  <?php

                                                                  mysql_free_result($Rssearch);

                                                                  ?>

                                                                  • 30. Re: search engine powered by data base in dw cs6?
                                                                    MurraySummers CommunityMVP

                                                                    Well, I think you might want to change this -

                                                                     

                                                                    $query_Rssearch = sprintf("SELECT * FROM books WHERE books.Title like %s OR books.Author like %s OR books.Publisher like %s OR books.ISBN like %s", GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"));

                                                                     

                                                                    to this -

                                                                     

                                                                    $query_Rssearch = sprintf("SELECT * FROM books WHERE books.Title like %s AND books.Author like %s AND books.Publisher like %s AND books.ISBN like %s", GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"));

                                                                     

                                                                    Then prefix the lines I suggested earlier to give this -

                                                                     

                                                                    if (!isset($_POST['Title']) && !isset($_POST['Author']) && !isset(...)) {

                                                                    $error ="You must complete a field to perform a search!";

                                                                    } else {

                                                                    $query_Rssearch = sprintf("SELECT * FROM books WHERE books.Title like %s AND books.Author like %s AND books.Publisher like %s AND books.ISBN like %s", GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"));

                                                                     

                                                                    Then change this (the end of that PHP block) -

                                                                     

                                                                    ?>

                                                                     

                                                                    to this -

                                                                     

                                                                    }

                                                                    ?>

                                                                     

                                                                    so that the entire search and associated PHP is skipped if none of those fields are completed.

                                                                     

                                                                    Finally, change this -

                                                                     

                                                                    <table border="1" align="center">

                                                                     

                                                                    to this -

                                                                     

                                                                    <?php if(isset($error)) { ?>

                                                                    <p style="color:red;"><?php echo $error; ?></p>

                                                                    <?php } else { ?>

                                                                    <table border="1" align="center">

                                                                     

                                                                    and this -

                                                                     

                                                                    </body>

                                                                     

                                                                    to this -

                                                                     

                                                                    <?php } ?>

                                                                    </body>

                                                                     

                                                                    See if that works.

                                                                    • 31. Re: search engine powered by data base in dw cs6?
                                                                      IVYY Community Member

                                                                      Hi Mentor,

                                                                       

                                                                      I tried out what you advised me. But it does not work, when I press the submit button without typing anything, it still displays all the results. moreover, it displays 2 error boxes with my search results too

                                                                       

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

                                                                      <?php

                                                                      if (!function_exists("GetSQLValueString")) {

                                                                      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                                                                      {

                                                                        if (PHP_VERSION < 6) {

                                                                          $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                                                                        }

                                                                       

                                                                       

                                                                        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                                                                       

                                                                       

                                                                        switch ($theType) {

                                                                          case "text":

                                                                            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                                            break;   

                                                                          case "long":

                                                                          case "int":

                                                                            $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                                                            break;

                                                                          case "double":

                                                                            $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                                                            break;

                                                                          case "date":

                                                                            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                                            break;

                                                                          case "defined":

                                                                            $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                                                            break;

                                                                        }

                                                                        return $theValue;

                                                                      }

                                                                      }

                                                                       

                                                                       

                                                                      $currentPage = $_SERVER["PHP_SELF"];

                                                                       

                                                                       

                                                                      $maxRows_Rssearch = 10;

                                                                      $pageNum_Rssearch = 0;

                                                                      if (isset($_GET['pageNum_Rssearch'])) {

                                                                        $pageNum_Rssearch = $_GET['pageNum_Rssearch'];

                                                                      }

                                                                      $startRow_Rssearch = $pageNum_Rssearch * $maxRows_Rssearch;

                                                                       

                                                                       

                                                                      $colname_Rssearch = "-100000000000000000000000000";

                                                                      if (isset($_GET['Search'])) {

                                                                        $colname_Rssearch = $_GET['Search'];

                                                                      }

                                                                       

                                                                       

                                                                       

                                                                       

                                                                      mysql_select_db($database_books, $books);

                                                                      if (!isset($_GET['Search'])) {

                                                                      $error ="You must complete a field to perform a search!";

                                                                      } else {

                                                                      $query_Rssearch = sprintf("SELECT * FROM books WHERE books.Title like %s OR books.Author like %s OR books.Publisher like %s OR books.ISBN like %s", GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"),GetSQLValueString("%" . $colname_Rssearch . "%", "text"));

                                                                      $Rssearch = mysql_query($query_Rssearch, $books) or die(mysql_error());

                                                                      $row_Rssearch = mysql_fetch_assoc($Rssearch);

                                                                      $totalRows_Rssearch = mysql_num_rows($Rssearch);

                                                                       

                                                                       

                                                                      $queryString_Rssearch = "";

                                                                      if (!empty($_SERVER['QUERY_STRING'])) {

                                                                        $params = explode("&", $_SERVER['QUERY_STRING']);

                                                                        $newParams = array();

                                                                        foreach ($params as $param) {

                                                                          if (stristr($param, "pageNum_Rssearch") == false &&

                                                                              stristr($param, "totalRows_Rssearch") == false) {

                                                                            array_push($newParams, $param);

                                                                          }

                                                                        }

                                                                        if (count($newParams) != 0) {

                                                                          $queryString_Rssearch = "&" . htmlentities(implode("&", $newParams));

                                                                        }

                                                                      }

                                                                      $queryString_Rssearch = sprintf("&totalRows_Rssearch=%d%s", $totalRows_Rssearch, $queryString_Rssearch);

                                                                      ?>

                                                                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                                                                      <html xmlns="http://www.w3.org/1999/xhtml">

                                                                      <head>

                                                                      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                                                                      <title>My Kino Result Page</title>

                                                                      </head>

                                                                       

                                                                       

                                                                      <body>

                                                                      <?php if(isset($error)) { ?>

                                                                      <p style="color:red;"><?php echo $error; ?></p>

                                                                      <?php } else { ?>

                                                                      <table border="1" align="center">

                                                                        <tr>

                                                                          <td>Images</td>

                                                                          <td>Title</td>

                                                                          <td>Author</td>

                                                                          <td>Publisher</td>

                                                                          <td>ISBN</td>

                                                                          <td>Price (S$)</td>

                                                                        </tr>

                                                                        <?php do { ?>

                                                                          <tr>

                                                                            <td><img src="Images/<?php echo $row_Rssearch['Images']; ?>" width="193" height="300" /> </td>

                                                                            <td><p> </p>

                                                                              <p><a href="My Kino Detailed Page.php?recordID=<?php echo $row_Rssearch['Title']; ?>"><?php echo $row_Rssearch['Title']; ?>  </a></p>

                                                                            <p> </p></td>

                                                                            <td><p> </p>

                                                                              <p><?php echo $row_Rssearch['Author']; ?> </p>

                                                                            <p> </p></td>

                                                                            <td><p> </p>

                                                                              <p><?php echo $row_Rssearch['Publisher']; ?>  </p>

                                                                            <p> </p></td>

                                                                            <td><p> </p>

                                                                              <p><?php echo $row_Rssearch['ISBN']; ?>  </p>

                                                                            <p> </p></td>

                                                                            <td><p> </p>

                                                                              <p><?php echo $row_Rssearch['Price (S$)']; ?></p>

                                                                            <p> </p>        <p> </p></td>

                                                                          </tr>

                                                                          <?php } while ($row_Rssearch = mysql_fetch_assoc($Rssearch)); ?>

                                                                      </table>

                                                                      <br />

                                                                      <table border="0">

                                                                        <tr>

                                                                          <td><?php if ($pageNum_Rssearch > 0) { // Show if not first page ?>

                                                                              <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, 0, $queryString_Rssearch); ?>">First</a>

                                                                              <?php } // Show if not first page ?></td>

                                                                          <td><?php if ($pageNum_Rssearch > 0) { // Show if not first page ?>

                                                                              <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, max(0, $pageNum_Rssearch - 1), $queryString_Rssearch); ?>">Previous</a>

                                                                              <?php } // Show if not first page ?></td>

                                                                          <td><?php if ($pageNum_Rssearch < $totalPages_Rssearch) { // Show if not last page ?>

                                                                              <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, min($totalPages_Rssearch, $pageNum_Rssearch + 1), $queryString_Rssearch); ?>">Next</a>

                                                                              <?php } // Show if not last page ?></td>

                                                                          <td><?php if ($pageNum_Rssearch < $totalPages_Rssearch) { // Show if not last page ?>

                                                                              <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, $totalPages_Rssearch, $queryString_Rssearch); ?>">Last</a>

                                                                              <?php } // Show if not last page ?></td>

                                                                        </tr>

                                                                      </table>

                                                                      <p>Records <?php echo ($startRow_Rssearch + 1) ?> to <?php echo min($startRow_Rssearch + $maxRows_Rssearch, $totalRows_Rssearch) ?> of <?php echo $totalRows_Rssearch ?>

                                                                      </p>

                                                                      <p><a href="My Kino Main Page.php">Main page</a></p>

                                                                      <?php } ?>

                                                                      </body>

                                                                      </html>

                                                                      <?php

                                                                      mysql_free_result($Rssearch);

                                                                      }

                                                                      ?>

                                                                      • 32. Re: search engine powered by data base in dw cs6?
                                                                        bregent CommunityMVP

                                                                        >Well, I think you might want to change this -

                                                                         

                                                                        Murray, at this point the OP said they want to use the same search field to search all 4 columns, so they would need to use OR rather than AND between the WHERE  clause expressions; right?

                                                                        • 33. Re: search engine powered by data base in dw cs6?
                                                                          MurraySummers CommunityMVP

                                                                          OK - I'll take a look.

                                                                          • 34. Re: search engine powered by data base in dw cs6?
                                                                            MurraySummers CommunityMVP

                                                                            Yes, I forgot that it was a single search field.

                                                                            • 35. Re: search engine powered by data base in dw cs6?
                                                                              IVYY Community Member

                                                                              Hi Mentor,

                                                                               

                                                                              I used show region server behaviour. I used show Recordset if not empty to show results in the master list when users type something. I used show recordset if empty to show error message when users never type something.

                                                                               

                                                                              But I have to set the default values of my record to be -1, and my WHERE clause expressions need to use = instead of the like and % wildcards for this to work.

                                                                               

                                                                              May I ask is it possible to still set my WHERE clause expressions with wildcards and also have the error page. Thanks!

                                                                               

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

                                                                              <?php

                                                                              if (!function_exists("GetSQLValueString")) {

                                                                              function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

                                                                              {

                                                                                if (PHP_VERSION < 6) {

                                                                                  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

                                                                                }

                                                                               

                                                                               

                                                                                $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

                                                                               

                                                                               

                                                                                switch ($theType) {

                                                                                  case "text":

                                                                                    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                                                    break;   

                                                                                  case "long":

                                                                                  case "int":

                                                                                    $theValue = ($theValue != "") ? intval($theValue) : "NULL";

                                                                                    break;

                                                                                  case "double":

                                                                                    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

                                                                                    break;

                                                                                  case "date":

                                                                                    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

                                                                                    break;

                                                                                  case "defined":

                                                                                    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

                                                                                    break;

                                                                                }

                                                                                return $theValue;

                                                                              }

                                                                              }

                                                                               

                                                                               

                                                                              $currentPage = $_SERVER["PHP_SELF"];

                                                                               

                                                                               

                                                                              $maxRows_Rssearch = 10;

                                                                              $pageNum_Rssearch = 0;

                                                                              if (isset($_GET['pageNum_Rssearch'])) {

                                                                                $pageNum_Rssearch = $_GET['pageNum_Rssearch'];

                                                                              }

                                                                              $startRow_Rssearch = $pageNum_Rssearch * $maxRows_Rssearch;

                                                                               

                                                                               

                                                                              $colname_Rssearch = "--1";

                                                                              if (isset($_GET['Search'])) {

                                                                                $colname_Rssearch = $_GET['Search'];

                                                                              }

                                                                              $colname1_Rssearch = "-1";

                                                                              if (isset($_GET['Price'])) {

                                                                                $colname1_Rssearch = $_GET['Price'];

                                                                              }

                                                                              mysql_select_db($database_books, $books);

                                                                              $query_Rssearch = sprintf("SELECT * FROM books WHERE books.Title = %s OR books.Author = %s OR books.Publisher = %s OR books.ISBN = %s OR (books.`Price (S$)`>= %s AND books.`Price (S$)`<= %s + 5)", GetSQLValueString($colname_Rssearch, "text"),GetSQLValueString($colname_Rssearch, "text"),GetSQLValueString($colname_Rssearch, "text"),GetSQLValueString($colname_Rssearch, "text"),GetSQLValueString($colname1_Rssearch, "int"),GetSQLValueString($colname1_Rssearch, "int"));

                                                                              $query_limit_Rssearch = sprintf("%s LIMIT %d, %d", $query_Rssearch, $startRow_Rssearch, $maxRows_Rssearch);

                                                                              $Rssearch = mysql_query($query_limit_Rssearch, $books) or die(mysql_error());

                                                                              $row_Rssearch = mysql_fetch_assoc($Rssearch);

                                                                               

                                                                               

                                                                              if (isset($_GET['totalRows_Rssearch'])) {

                                                                                $totalRows_Rssearch = $_GET['totalRows_Rssearch'];

                                                                              } else {

                                                                                $all_Rssearch = mysql_query($query_Rssearch);

                                                                                $totalRows_Rssearch = mysql_num_rows($all_Rssearch);

                                                                              }

                                                                              $totalPages_Rssearch = ceil($totalRows_Rssearch/$maxRows_Rssearch)-1;

                                                                               

                                                                               

                                                                              $queryString_Rssearch = "";

                                                                              if (!empty($_SERVER['QUERY_STRING'])) {

                                                                                $params = explode("&", $_SERVER['QUERY_STRING']);

                                                                                $newParams = array();

                                                                                foreach ($params as $param) {

                                                                                  if (stristr($param, "pageNum_Rssearch") == false &&

                                                                                      stristr($param, "totalRows_Rssearch") == false) {

                                                                                    array_push($newParams, $param);

                                                                                  }

                                                                                }

                                                                                if (count($newParams) != 0) {

                                                                                  $queryString_Rssearch = "&" . htmlentities(implode("&", $newParams));

                                                                                }

                                                                              }

                                                                              $queryString_Rssearch = sprintf("&totalRows_Rssearch=%d%s", $totalRows_Rssearch, $queryString_Rssearch);

                                                                              ?>

                                                                              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                                                                              <html xmlns="http://www.w3.org/1999/xhtml">

                                                                              <head>

                                                                              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                                                                              <title>My Kino Result Page</title>

                                                                              </head>

                                                                               

                                                                               

                                                                              <body>

                                                                               

                                                                               

                                                                              <table border="1" align="center">

                                                                                <tr>

                                                                                  <td>Images</td>

                                                                                  <td>Title</td>

                                                                                  <td>Author</td>

                                                                                  <td>Publisher</td>

                                                                                  <td>ISBN</td>

                                                                                  <td>Price (S$)</td>

                                                                                </tr>

                                                                                <?php do { ?>

                                                                                    <?php if ($totalRows_Rssearch > 0) { // Show if recordset not empty ?>

                                                                                <tr>

                                                                                  <td><img src="Images/<?php echo $row_Rssearch['Images']; ?>" width="193" height="300" /> </td>

                                                                                  <td><p> </p>

                                                                                    <p><a href="My Kino Detailed Page.php?recordID=<?php echo $row_Rssearch['Title']; ?>"><?php echo $row_Rssearch['Title']; ?>  </a></p>

                                                                                    <p> </p></td>

                                                                                  <td><p> </p>

                                                                                    <p><?php echo $row_Rssearch['Author']; ?> </p>

                                                                                    <p> </p></td>

                                                                                  <td><p> </p>

                                                                                    <p><?php echo $row_Rssearch['Publisher']; ?>  </p>

                                                                                    <p> </p></td>

                                                                                  <td><p> </p>

                                                                                    <p><?php echo $row_Rssearch['ISBN']; ?>  </p>

                                                                                    <p> </p></td>

                                                                                  <td><p> </p>

                                                                                    <p><?php echo $row_Rssearch['Price (S$)']; ?></p>

                                                                                    <p> </p>        <p> </p></td>

                                                                                </tr>

                                                                                <?php } // Show if recordset not empty ?>

                                                                              <?php } while ($row_Rssearch = mysql_fetch_assoc($Rssearch)); ?>

                                                                              </table>

                                                                              <p><?php if ($totalRows_Rssearch == 0) { // Show if recordset empty ?>

                                                                                <p>We're sorry, the term that you just searched is not in the database. Please try again!</p>

                                                                                <?php } // Show if recordset empty ?><br />

                                                                              </p>

                                                                              <table border="0">

                                                                                <tr>

                                                                                  <td><?php if ($pageNum_Rssearch > 0) { // Show if not first page ?>

                                                                                      <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, 0, $queryString_Rssearch); ?>">First</a>

                                                                                  <?php } // Show if not first page ?></td>

                                                                                  <td><?php if ($pageNum_Rssearch > 0) { // Show if not first page ?>

                                                                                      <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, max(0, $pageNum_Rssearch - 1), $queryString_Rssearch); ?>">Previous</a>

                                                                                  <?php } // Show if not first page ?></td>

                                                                                  <td><?php if ($pageNum_Rssearch < $totalPages_Rssearch) { // Show if not last page ?>

                                                                                      <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, min($totalPages_Rssearch, $pageNum_Rssearch + 1), $queryString_Rssearch); ?>">Next</a>

                                                                                  <?php } // Show if not last page ?></td>

                                                                                  <td><?php if ($pageNum_Rssearch < $totalPages_Rssearch) { // Show if not last page ?>

                                                                                      <a href="<?php printf("%s?pageNum_Rssearch=%d%s", $currentPage, $totalPages_Rssearch, $queryString_Rssearch); ?>">Last</a>

                                                                                  <?php } // Show if not last page ?></td>

                                                                                </tr>

                                                                              </table>

                                                                              <p>Records <?php echo ($startRow_Rssearch + 1) ?> to <?php echo min($startRow_Rssearch + $maxRows_Rssearch, $totalRows_Rssearch) ?> of <?php echo $totalRows_Rssearch ?>

                                                                              </p>

                                                                              <p><a href="My Kino Main Page.php">Main page</a></p>

                                                                              </body>

                                                                              </html>

                                                                              <?php

                                                                              mysql_free_result($Rssearch);

                                                                              ?>

                                                                              • 36. Re: search engine powered by data base in dw cs6?
                                                                                MurraySummers CommunityMVP

                                                                                With the exception of this -

                                                                                 

                                                                                $colname_Rssearch = "--1";

                                                                                 

                                                                                (shouldn't "--1" be "-1"?)

                                                                                 

                                                                                this code looks OK. What is the problem with it?

                                                                                • 37. Re: search engine powered by data base in dw cs6?
                                                                                  IVYY Community Member

                                                                                  Hi,

                                                                                   

                                                                                  The problem is that I cannot have the wildcard function ('like' and '%') to make my search textfield very smart. For example: Users now need to really type the specific title, author or publisher to get the relevant result page.

                                                                                   

                                                                                  SELECT *

                                                                                  FROM books

                                                                                  WHERE books.Title = colname OR books.Author = colname OR books.Publisher = colname OR books.ISBN = colname OR (books.`Price (S$)`>= colname1 AND books.`Price (S$)`<= colname1 + 5)

                                                                                   

                                                                                  How should I solve it?

                                                                                   

                                                                                  Thanks!

                                                                                  • 39. Re: search engine powered by data base in dw cs6?
                                                                                    IVYY Community Member

                                                                                    Hi Ben,

                                                                                     

                                                                                    I have downloaded it but I am not sure how do I integrate it into my main page. May you give some advice on it?

                                                                                    1 2 Previous Next