Jump to content

XandarX

Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by XandarX

  1. Solved it. Used the split function then search for the words individually. Didn't need fulltext and that's what EVERYONE was telling me to do.... ugh. Keyword order counts in mysql.
  2. Simple. You need to make the ORDER BY a string rather than static in your query. In the form have a hidden field. <input type=hidden name="order" value="state_abbreviation"> Then on the query: $state = mysql_query("SELECT state_abbreviation FROM state ORDER BY $order ASC", $connect);
  3. Wasn't able to do anything with that bit, though it's a good piece of code for what it does. Might use something like that in another application I'm making! Where I'm having trouble is that MySQL returns results only for the string of words that are found IN ORDER. But if the database has the item in reversed order, it does not return it. Example: Search string "David Bowie" only returns results with "David Bowie", NOT "Bowie David" I need it to return the results no matter the order they appear in within the database. I'm using mySQL 5.0.91 and php 5.2.9 if that makes a difference. I tried using BOOLEAN and NATURAL LANGUAGE modes in my query, but the results were the same. Still the same order. What I think I need is to split the search string up into parts, pass each one to the query individually to build some sort of a recordset, then return only the results that have all of the keywords entered. I've done this exact same type of search in asp, but php doesn't seem to have the same functionality when it comes to data recordsets. I'm learning, but I need some help. I researched fulltext and figured out that was somewhere in the neighborhood, but when I implemented it the results never changed. Keyword order seems to matter and I can't figure out how to get around that.
  4. I worded my question wrong. For that I apologize. What I meant was this: User types in "Faith Hill" I need the search script to return all records with "Faith Hill" AND "Hill, Faith" Though looking at the examples you gave I'm starting to get a better understanding of what might be going wrong. The problem is that I really don't know how to implement it. I changed my text fields in the database to add fulltext to them. All my internet searches on the subject state that I need to do something in a fulltext method, even though they don't quite tell you how.
  5. I have some data in a table and some of it is Artist names stored as "Last, First" I need to be able to have the script search weather or not someone types "last, first" or "first last". Any ideas? Here's my code: <html> <head> <title>search script</title> </head> <body> <form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=100; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","username","password"); //(host, username, password) //specify database mysql_select_db("mydb") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from songs where Title like \"%$trimmed%\" or Artist like \"%$trimmed%\" order by Title"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned echo "<table border=1>"; while ($row= mysql_fetch_array($result)) { $title = $row["Title"]; $artist = $row["Artist"]; $number = $row["Number"]; echo "<tr><td>$count.)</td><td>$title</td><td>$artist</td><td>$number</td></tr>" ; $count++ ; } echo "</table>"; $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>&nbsp "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 20 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> </body> </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.