I am a middle school geography teacher learning web programming.
For my school, I am creating a single-page multi-tab portal with four jquery tabs. I'd like the fourth tab to contain a form and also search & display MySQL query results.
My problem is, on the fourth tab, once I enter the search term and hit the "Search" button, the results are not loading in the fourth tab. They are loading on a separate page: http://localhost/notes_search.php
How could I get the results to appear in the fourth tab, below the search form?
Another way to look at this problem: I am successfully able to get the (1) tabs functioning separately (2) search results load in a single (no tab) page separately. I am missing something as I try to combine these two features.
Please help. Thank you very much.
-Susana
#######################
This is what I have on the php file for the fourth tab (page_4.php):
-
- <div id="notescontainer">
-
- <div>
-
- <form method="post" action="notes_search.php">
-
- <input type="text" name="search" id="notes_search_box" class="notes_search_box"/>
-
- <input type="submit" value="Search" class="notes_search_button" /><br />
-
- </form>
-
- </div>
-
- <div>
-
- <div id="notes_searchresults">Search results :</div>
-
- <div id="notes_results" class="update"></div>
-
- </div>
-
- </div>
-
-
#######################
This is what I have for search and display: notes_search.php
-
- <?php
-
-
-
-
-
- define('INCLUDE_CHECK',true);
-
-
-
- require 'connect.php';
-
-
-
-
-
- //if we got something through $_POST
-
- if (isset($_POST['search'])) {
-
-
-
- // never trust what user wrote! We must ALWAYS sanitize user input
-
- $word = mysql_real_escape_string($_POST['search']);
-
-
-
- // build your search query to the database
-
- $result = mysql_query("select * from notes where notes like '%".$word."%'");
-
-
-
- // get results
-
- while($row = mysql_fetch_array($result))
-
- {
-
- echo "<p>".$row['notes'];
-
- }
-
- }
-
- ?>
-
-
#######################
And finally, here's the JavaScript on the main page of the portal: index.php
- <SCRIPT>
-
-
-
- $(function() {
-
-
-
- $(".notes_search_button").click(function() {
-
- // getting the value that user typed
-
- var searchString = $("#notes_search_box").val();
-
- // forming the queryString
-
- var data = 'search='+ searchString;
-
-
-
- // if searchString is not empty
-
- if(searchString) {
-
- // ajax call
-
- $.ajax({
-
- type: "POST",
-
- url: "notes_search.php",
-
- data: data,
-
- beforeSend: function(html) { // this happens before actual call
-
- $("#notes_results").html('');
-
- $("#notes_searchresults").show();
-
- $(".word").html(searchString);
-
- },
-
- success: function(html){ // this happens after we get results
-
- $("#notes_results").show();
-
- $("#notes_results").append(html);
-
- }
-
- });
-
- }
-
- return false;
-
- });
-
- });
-
-
- </script>