Skip navigation
Currently Being Moderated

search engine powered by data base in dw cs6?

Mar 21, 2013 7:46 AM

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!

 
Replies 1 2 Previous Next
  • Currently Being Moderated
    Mar 21, 2013 8:02 AM   in reply to IVYY

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2013 9:21 AM   in reply to IVYY

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2013 9:41 AM   in reply to IVYY

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2013 9:52 AM   in reply to IVYY

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2013 11:48 AM   in reply to IVYY

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2013 5:57 AM   in reply to IVYY

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2013 6:16 AM   in reply to IVYY

    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']; ?>">

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2013 10:52 AM   in reply to IVYY

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2013 11:29 AM   in reply to IVYY

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 4:41 AM   in reply to IVYY

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 4:47 AM   in reply to MurraySummers

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 11:41 AM   in reply to IVYY

    <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); ?>

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 8:14 AM   in reply to IVYY

    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 } ?>

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 9:12 AM   in reply to IVYY

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 11:54 AM   in reply to MurraySummers

    >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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 12:32 PM   in reply to IVYY

    OK - I'll take a look.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 12:32 PM   in reply to bregent

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 27, 2013 8:34 AM   in reply to IVYY

    With the exception of this -

     

    $colname_Rssearch = "--1";

     

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

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2013 6:24 AM   in reply to IVYY
     
    |
    Mark as:
1 2 Previous Next

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points