Jump to content

mrelliott

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mrelliott's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Try printing out your queries and see what they are sending. You place this under the query code print $yourqueryname; and run the page. I had an empty string in a count(*) query that I was able to fix by moving another line of code that was above the only other query I had on the page. That code was working because it was underneath the code I needed to move and the count code was not. Because the count code wasn't working properly my links where not showing up.
  2. Hope this helps, I'm pretty new at this. Try changing these: echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."[/url] "); echo("<a href=\"$PHP_SELF?page=$i\">$i[/url] "); echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."[/url]"); To these: echo '<a href="'.$PHP_SELF.'&page= '. $pageprev.'">PREV '.$limit.'"</a> '; echo '<a href="'.$PHP_SELF.'?page='. $i.'"> '.$i.'</a> '; echo '<a href="'.$PHP_SELF.'?page='. $pagenext.'">NEXT '.$limit.'"</a> '; And make sure to keep the space between the last > and ' or your page numbers will clump together. I'm not sure if this would help either but you might want to try replacing $PHP_SELF with $_SERVER['PHP_SELF']
  3. It was pointed out to me on another forum that my counting code had an empty string which showed up when I printed the code. The second piece of code was working properly (the string was full). I was looking at a printout of the whole code and deceided to try something. AND IT ACTUALLY WORKED!!! I had to move the following piece of code $searchwords = mysql_escape_string($_GET['words']); from the middle of my page, just above the $sql code which was working (because this line was above it) and place it at the start of my code above the counting code which was not working (because this line of code was NOT above it). After three months of wondering what in the world I was doing wrong!!! Finally!!!
  4. I was told that I should print out the codes. The only thing I can think of is that I have a problem with the count code. $query = "SELECT COUNT(*) FROM master_list WHERE MATCH(album) AGAINST('$searchwords') ORDER BY song_id"; print $query; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; print $result; print $row; print $num_records; The result: SELECT COUNT(*) FROM master_list WHERE MATCH(album) AGAINST('') ORDER BY song_id Resource id #3 Array0 The code: $sql = "SELECT song_id, title, album, writer FROM master_list WHERE MATCH(album) AGAINST('$searchwords')ORDER BY title LIMIT $start, $display"; print $sql; $result = mysql_query($sql) or die (mysql_error()); print $result; The result: SELECT song_id, title, album, writer FROM master_list WHERE MATCH(album) AGAINST('flash gordon')ORDER BY title LIMIT 0, 10 Resource id #4
  5. I'm having a dumb moment. Can you show me a code example. I took an online course on this and for some reason they never covered paginating a user's search. I really wish they would have, if they did I wouldn't be fighting this for the past three months now. I'm looking back on my session notes. I've placed this at the top of my search page: <?php session_start(); $_SESSION['search'] ='$searchwords'; $_SESSION['results'] ='$searchstring'; ?> And this at the top of my results page: <?php session_start(); ?> I didn't get any error messages, but it didn't help get my results past the first ten.
  6. Do I replace while ($row = mysql_fetch_object($result, MYSQL_ASSOC)) { with this new piece of code?
  7. In all the other pages that have that same code (and have more then ten results) the first page displays ten and the next page displays another ten (if there is ten more) and so on. Here's an example: <?php # song_list.php // This script retrieves all the records from the master_list table. require_once ('./includes/mysql_connect.php'); // Connect to the db. //Records to display per page. $display = 10; //Check if the number of required pages has been determined. if (isset($_GET['np'])) { //Already been determined. $num_pages = $_GET['np']; } else { //Need to determine. // Count the number of records $query = "SELECT COUNT(*) FROM master_list WHERE album ='Flash Gordon' ORDER BY track"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; //calculate number of pages. if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } //end of np if. //where to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } //Default column links. Removed space between} and? this was the problem with the links. $link1 = "{$_SERVER['PHP_SELF']}?sort=tracka"; $link2 = "{$_SERVER['PHP_SELF']}?sort=titlea"; $link3 = "{$_SERVER['PHP_SELF']}?sort=lengtha"; $link4 = "{$_SERVER['PHP_SELF']}?sort=writera"; //sorting order determined? if (isset($_GET['sort'])) { //switch conditional. switch ($_GET['sort']) { case 'tracka': $order_by = 'track ASC'; $link1 = "{$_SERVER['PHP_SELF'] }?sort=trackd"; break; case 'trackd': $order_by = 'track DESC'; $link1 = "{$_SERVER['PHP_SELF'] }?sort=tracka"; break; case 'titlea': $order_by = 'title ASC'; $link2 = "{$_SERVER['PHP_SELF'] }?sort=titled"; break; case 'titled': $order_by = 'title DESC'; $link2 = "{$_SERVER['PHP_SELF'] }?sort=titlea"; break; case 'lengtha': $order_by = 'length ASC'; $link3 = "{$_SERVER['PHP_SELF'] }?sort=lengthd"; break; case 'lengthd': $order_by = 'length DESC'; $link3 = "{$_SERVER['PHP_SELF'] }?sort=lengtha"; break; case 'writera': $order_by = 'writer ASC'; $link4 = "{$_SERVER['PHP_SELF'] }?sort=writerd"; break; case 'writerd': $order_by = 'writer DESC'; $link4 = "{$_SERVER['PHP_SELF'] }?sort=writera"; break; default: $order_by = 'track ASC'; break; } // $sort will be appended to the pagination links. $sort = $_GET['sort']; } else { //use default sorting order. $order_by = 'track ASC'; //missing single quote before semicolon. $sort = 'tracka'; } // Make the query. $query = "SELECT track, title, TIME_FORMAT( length, '%i:%S') AS length, album, writer, song_id FROM master_list WHERE album ='Flash Gordon' ORDER BY $order_by LIMIT $start, $display"; $result = @mysql_query ($query); // Run the query. //Album Titles define (ALBUM_1, 'Queen (1973)'); define (ALBUM_2, 'Queen II (1974)'); define (ALBUM_3, 'Sheer Heart Attack (1974)'); define (ALBUM_4, 'A Night at the Opera (1975)'); define (ALBUM_5, 'A Day at the Races (1976)'); define (ALBUM_6, 'News of the World (1977)'); define (ALBUM_7, 'Jazz (1978)'); define (ALBUM_8, 'The Game (1980)'); define (ALBUM_9, 'Flash Gordon (1980)'); define (ALBUM_10, 'Hot Space (1982)'); define (ALBUM_11, 'The Works (1984)'); define (ALBUM_12, 'A Kind of Magic (1986)'); define (ALBUM_13, 'The Miracle (1989)'); define (ALBUM_14, 'Innuendo (1991)'); define (ALBUM_15, 'Made in Heaven (1995)'); echo '<center>'.ALBUM_9.'</center>'; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"><tr> <td align="left"><b><font size="-1"><a href="' . $link1 . '">Track</a></font></b></td> <td align="left"><b><font size="-1"><a href="' . $link2 . '">Song Title</a></font></b></td> <td align="left"><b><font size="-1"><a href="' . $link3 . '">Song Length</a></font></b></td> <td align="left"><b><font size="-1"><a href="' . $link4 . '">Writer</a></font></b></td> </tr> '; // Fetch and print all the records. $bg = '#000066'; //Background display. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg=='#000066' ? '#003399' : '#000066'); //switch the bg color. echo '<tr bgcolor="' . $bg . '"> <td align="left"><font size="-1">' . $row['track'] . '</font></td> <td align="left"><font size="-1">' . $row['title'] . '</font></td> <td align="left"><font size="-1">' . $row['length'] . '</font></td> <td align="left"><font size="-1">' . $row['writer'] . '</font></td> </tr> '; } echo '</table>'; mysql_free_result ($result); // Free up the resources. mysql_close(); //Close connection. // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="flashgordon.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="flashgordon.php?s='.(($display * ($i - 1))).'&np='.$num_pages.'&sort='.$sort.'">' .$i. '</a> '; } else { echo $i.' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="flashgordon.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a> '; } echo '</p>'; } // End of links section. ?> It displays a list of 18 song titles and other info on two pages. Ten on the first, eight on the next page. Why is this not working with a full text search?
  8. I've seperated out my search page from my results page. Search page code. <?php $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); echo '<form name="form1" method="get" action="searchtitle.php">'; echo 'Search by Title:'; echo '<input type="text" name="words" value="'.$searchwords.'">'; echo '<input type="submit" name="Submit" value="Submit">'; echo '</form>'; ?> <br /> <?php $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); echo '<form name="form2" method="get" action="searchalbum.php">'; echo 'Search by Album:'; echo '<input type="text" name="words" value="'.$searchwords.'">'; echo '<input type="submit" name="Submit" value="Submit">'; echo '</form>'; ?> <br /> <?php $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); echo '<form name="form3" method="get" action="searchwriter.php">'; echo 'Search by Writer:'; echo '<input type="text" name="words" value="'.$searchwords.'">'; echo '<input type="submit" name="Submit" value="Submit">'; echo '</form>'; ?> Results page for an Album search: <?php // Full-Text Search Example // Connect to the database. require_once ('./includes/mysql_connect.php'); //connect to database //Records to display per page. $display = 10; //Check if the number of required pages has been determined. if (isset($_GET['np'])) { //Already been determined. $num_pages = $_GET['np']; } else { //Need to determine. // Count the number of records $query = "SELECT COUNT(*) FROM master_list WHERE album='$searchstring' ORDER BY song_id"; //$result = mysql_query($query); //$num_records = mysql_num_rows($result); $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; //calculate number of pages. if ($num_records > $display) { $num_pages = ceil($num_records/$display); } else { $num_pages = 1; } } //end of np if. //where to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } $searchstring = mysql_escape_string($_GET['words']); { $sql = "SELECT song_id, title, album, writer FROM master_list WHERE album='$searchstring' ORDER BY title LIMIT $start, $display"; //$sql = "SELECT song_id, title, album, writer, MATCH (title, album, writer) AGAINST ('$searchstring') FROM master_list //WHERE MATCH(title, album, writer) AGAINST ('$searchstring') ORDER BY title LIMIT $start, $display"; } $result = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_object($result, MYSQL_ASSOC)) { //while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //while($row = mysql_fetch_object($result)){ echo '<font size="-1">Title: '.stripslashes(htmlspecialchars($row->title)).'<br /></font>'; echo '<font size="-1">Album: '.stripslashes(htmlspecialchars($row->album)).'<br /></font>'; echo '<font size="-1">Writer: '.stripslashes(htmlspecialchars($row->writer)).'<br /></font>'; echo '<hr size="-1" />'; } // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="searchalbum.php?s='.($start - $display).'&np='.$num_pages.'&words='.$searchwords .'">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="searchalbum.php?s='.(($display * ($i - 1))).'&np='.$num_pages.'&words='.$searchwords.'">'.$i.'</a> '; } else { echo $i.' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="searchalbum.php?s='.($start + $display).'&np='.$num_pages.'&words='.$searchwords.'">Next</a> '; } echo '</p>'; } // End of links section. ?> The first ten results are displayed and I know there's more. What am I doing wrong here I can't figure it out.
  9. Can somebody PLEASE just read through this and tell me what am I doing wrong with this code. Why can't I get the page links to display at the bottom of the page. What am I missing here! Here's the full code. It does look up words but will only display a max of 10 even when I know there's more. If there's something wrong with it tell me, I'm new with this and I'm getting ready to just give up. <?php // Full-Text Search Example // Connect to the database. require_once ('./includes/mysql_connect.php'); //connect to database //Records to display per page. $display = 10; //Check if the number of required pages has been determined. if (isset($_GET['np'])) { //Already been determined. $num_pages = $_GET['np']; } else { //Need to determine. // Count the number of records $query = "SELECT COUNT(*) FROM master_list WHERE MATCH(title, album, writer) AGAINST('$searchstring') ORDER BY song_id"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_NUM); $num_records = $row[0]; //calculate number of pages. if ($num_records > $display) { $num_pages = ceil($num_records/$display); } else { $num_pages = 1; } } //end of np if. //where to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Create the search function: function searchForm() { // Re-usable form // variable setup for the form. $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' ); $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' ); echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">'; echo '<input type="hidden" name="cmd" value="search" />'; echo '<font size="-1">Search for: <input type="text" name="words" value="'.$searchwords.'" /></font> '; echo '<font size="-1">Mode: </font>'; echo '<select name="mode">'; echo '<option value="normal"'.$normal.'>Normal</option>'; echo '<option value="boolean"'.$boolean.'>Boolean</option>'; echo '</select> '; echo '<input type="submit" value="Search" />'; echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) { default: echo '<h1><font size="-1">Search Database!</font></h1>'; searchForm(); break; case "search": searchForm(); echo '<h3><font size="-1">Search Results:</font></h3><br />'; $searchstring = mysql_escape_string($_GET['words']); switch($_GET['mode']) { case "normal": $sql = "SELECT song_id, title, album, writer, MATCH (title, album, writer) AGAINST ('$searchstring') FROM master_list WHERE MATCH(title, album, writer) AGAINST ('$searchstring') ORDER BY title LIMIT $start, $display"; break; case "boolean": $sql = "SELECT song_id, title, album, writer, MATCH (title, album, writer) AGAINST ('$searchstring' IN BOOLEAN MODE) FROM master_list WHERE MATCH(title, album, writer) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY title LIMIT $start, $display"; break; } // echo $sql; $result = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_object($result)){ echo '<font size="-1">Title: '.stripslashes(htmlspecialchars($row->title)).'<br /></font>'; echo '<font size="-1">Album: '.stripslashes(htmlspecialchars($row->album)).'<br /></font>'; echo '<font size="-1">Writer: '.stripslashes(htmlspecialchars($row->writer)).'<br /></font>'; echo '<hr size="-1" />'; } break; } // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="searchresults3.php?s='.($start - $display).'&np='.$num_pages.'&words='.$searchwords .'">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="searchresults3.php?s='.(($display * ($i - 1))).'&np='.$num_pages.'&words='.$searchwords.'">'.$i.'</a> '; } else { echo $i.' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="searchresults3.php?s='.($start + $display).'&np='.$num_pages.'&words='.$searchwords.'">Next</a> '; } echo '</p>'; } // End of links section. ?>
  10. Can somebody PLEASE show me how to set up my counting code to select only what's being searched for and not everything in the table. I've been trying this for days. When I actually seem to get a result that works only ten results are listed with no page links at the bottom of the screen or (as in the case of the code below) it lists page links but all results disappear when one is clicked, even from the first page. <?php // Full-Text Search Example // Connect to the database. require_once ('./includes/mysql_connect.php'); //connect to database //Records to display per page. $display = 10; //Check if the number of required pages has been determined. if (isset($_GET['np'])) { //Already been determined. $num_pages = $_GET['np']; } else { //Need to determine. //I need this code to select only what's been entered into the search bar. The columns I need to count from are title, album and writer. // Count the number of records $query = "SELECT COUNT(*) FROM master_list ORDER BY song_id"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; //calculate number of pages. if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } //end of np if. //where to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Create the search function: function searchForm() { // Re-usable form // variable setup for the form. $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' ); $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' ); echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">'; echo '<input type="hidden" name="cmd" value="search" />'; echo '<font size="-3">Search for: <input type="text" name="words" value="'.$searchwords.'" /></font> '; echo '<font size="-3">Mode: </font>'; echo '<select name="mode">'; echo '<option value="normal"'.$normal.'>Normal</option>'; echo '<option value="boolean"'.$boolean.'>Boolean</option>'; echo '</select> '; echo '<input type="submit" value="Search" />'; echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) { default: //echo '<h1><font size="-3">Search Database!</font></h1>'; searchForm(); break; case "search": searchForm(); //echo '<h3><font size="-3">Search Results:</font></h3><br />'; $searchstring = mysql_escape_string($_GET['words']); switch($_GET['mode']) { case "normal": $sql = "SELECT song_id, title, album, writer, MATCH (title, album, writer) AGAINST ('$searchstring') FROM master_list WHERE MATCH(title, album, writer) AGAINST ('$searchstring') ORDER BY title LIMIT $start, $display"; break; case "boolean": $sql = "SELECT song_id, title, album, writer, MATCH (title, album, writer) AGAINST ('$searchstring' IN BOOLEAN MODE) FROM master_list WHERE MATCH(title, album, writer) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY title LIMIT $start, $display"; break; } // echo $sql; $result = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_object($result)){ echo '<font size="-3">Title: '.stripslashes(htmlspecialchars($row->title)).'<br /></font>'; echo '<font size="-3">Album: '.stripslashes(htmlspecialchars($row->album)).'<br /></font>'; echo '<font size="-3">Writer: '.stripslashes(htmlspecialchars($row->writer)).'<br /></font>'; echo '<hr size="-3" />'; } break; } // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="searchresults2.php?s=' . ($start - $display) . '&np=' . $num_pages . '&words=' . $searchstring .'">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="searchresults2.php?s='.(($display * ($i - 1))).'&np='.$num_pages.'&words='.$searchstring .'">'.$i.'</a> '; } else { echo $i.' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="searchresults2.php?s=' . ($start + $display) . '&np=' . $num_pages . '&words=' . $searchstring .'">Next</a> '; } echo '</p>'; } // End of links section. ?>
  11. I'm new at PHP and MySQL. I've used the tutorial on this site to set up a search engine for a database of songs for the band Queen. It does find results but I've run into some problems. I'm having difficulty figuring out how to set up a session that will store the search results collected, they disappear after I click on page 2. And I had read somewhere else on this forum that the results should be stored in a session, but I can't find that topic anymore. Also I want to set up the pages so that the search results determine how many pages are needed. What I have set up in the count function section of the code counts all the records in my song table and I want it to count the full text index if that's possible. Here's my code. <?php session_start(); ?> <html><!-- #BeginTemplate "/Templates/queenlayout.dwt" --> <head> <!-- #BeginEditable "doctitle" --> <title>Queen Album & Song Database -- Search Results</title> <!-- #EndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#000066" text="#CCCCCC" link="#CCCCCC" vlink="#CCCCCC" alink="#CCCCCC"> <div align="center"> <table width="98%" border="0" height="116"> <tr> <td height="36"> <div align="center"></div> <div align="center"></div> <div align="center"><!-- #BeginEditable "header" --> <?php include ('./includes/queenheader.html'); ?> <!-- #EndEditable --></div> <div align="center"></div> </td> </tr> <tr> <td height="483"> <div align="center"></div> <div align="center"></div> <div align="center"><!-- #BeginEditable "results" --> <?php // Full-Text Search Example // Conect to the database. require_once ('./includes/mysql_connect.php'); //connect to database //Records to display per page. $display = 10; //Check if the number of required pages has been determined. if (isset($_GET['np'])) { //Already been determined. $num_pages = $_GET['np']; } else { //Need to determine. // Count the number of records $query = "SELECT COUNT(*) FROM master_list ORDER BY song_id"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; //calculate number of pages. if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } //end of np if. //where to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Create the search function: function searchForm() { // Re-usable form // variable setup for the form. $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' ); $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' ); echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">'; echo '<input type="hidden" name="cmd" value="search" />'; echo '<font size="-3">Search for: <input type="text" name="words" value="'.$searchwords.'" /></font> '; echo '<font size="-3">Mode: </font>'; echo '<select name="mode">'; echo '<option value="normal"'.$normal.'>Normal</option>'; echo '<option value="boolean"'.$boolean.'>Boolean</option>'; echo '</select> '; echo '<input type="submit" value="Search" />'; echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) { default: //echo '<h1><font size="-3">Search Database!</font></h1>'; searchForm(); break; case "search": searchForm(); //echo '<h3><font size="-3">Search Results:</font></h3><br />'; $searchstring = mysql_escape_string($_GET['words']); switch($_GET['mode']) { case "normal": $sql = "SELECT song_id, title, album, writer, MATCH(title, album, writer) AGAINST ('$searchstring') AS score FROM master_list WHERE MATCH(title, album, writer) AGAINST ('$searchstring') ORDER BY score DESC LIMIT $start, $display"; break; case "boolean": $sql = "SELECT song_id, title, album, writer, MATCH(title, album, writer) AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM master_list WHERE MATCH(title, album, writer) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC LIMIT $start, $display"; break; } // echo $sql; $result = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_object($result)) { echo '<font size="-3"><strong>Title: '.stripslashes(htmlspecialchars($row->title)).'</strong><br /></font>'; echo '<font size="-3">Score:'. number_format($row->score, 1).' Album: '.stripslashes(htmlspecialchars($row->album)).'<br /></font>'; echo '<font size="-3"><p>Writer: '.stripslashes(htmlspecialchars($row->writer)).'</p></font>'; echo '<hr size="-3" />'; } break; } //mysql_free_result ($result); // Free up the resources. mysql_close(); //Close connection. // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="searchresults.php?s=' . ($start - $display) . '&np=' . $num_pages .'">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="searchresults.php?s='.(($display * ($i - 1))).'&np='.$num_pages .'">'.$i.'</a> '; } else { echo $i.' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="searchresults.php?s=' . ($start + $display) . '&np=' . $num_pages .'">Next</a> '; } echo '</p>'; } // End of links section. ?> <!-- #EndEditable --></div> </td> </tr> <tr> <td height="27"> <div align="center"><!-- #BeginEditable "footer" --> <?php include ('./includes/queenfooter.html'); ?> <!-- #EndEditable --></div> </td> </tr> </table> </div> </body> <!-- #EndTemplate --></html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.