MySQL Forums
Forum List  »  Full-Text Search

HELP - Adding pagination and view details to this full-text search?
Posted by: Lion
Date: October 11, 2006 10:00PM

How would I add pagination to the results of this search? I've tried several ways but I'm stumped.


<?php
// Full-Text Search Example
// Conect to the database.
$cnx = mysql_connect('localhost', 'root', 'root') or die ("Could not connect");
mysql_select_db('dbname', $cnx) or die (mysql_error());

// 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 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';
echo 'Mode: ';
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>Search Database!</h1>';
searchForm();

break;


case "search":
searchForm();
echo '<h3>Search Results:</h3><br />';

$searchstring = mysql_escape_string($_GET['words']);
switch($_GET['mode'])
{
case "normal":
$sql = "SELECT name, shortdescription, city, county,
MATCH(name, shortdescription, description, address, city, zipcode, county)
AGAINST ('$searchstring') AS score FROM st
WHERE MATCH(name, shortdescription, description, address, city, zipcode, county)
AGAINST ('$searchstring') ORDER BY score DESC";
break;

case "boolean":
$sql = "SELECT name, shortdescription, city, county,
MATCH(name, shortdescription, description, address, city, zipcode, county)
AGAINST ('$searchstring'IN BOOLEAN MODE) AS score FROM st
WHERE MATCH(name, shortdescription, description, address, city, zipcode, county)
AGAINST ('$searchstring'IN BOOLEAN MODE) ORDER BY score DESC";
break;
}


// echo $sql;

$result = mysql_query($sql) or die (mysql_error());

while($row = mysql_fetch_object($result))
{
echo '<strong><img src="images/mm_arrow.gif"> <font color="#FF6600">'.stripslashes(htmlspecialchars($row->name)).'</font></strong><br />';
echo 'Score:'. number_format($row->score, 1).' City: '.stripslashes(htmlspecialchars($row->city)).' County: '.stripslashes(htmlspecialchars($row->county)).' <br/>';
echo '<p>'.stripslashes(htmlspecialchars($row->shortdescription)).'</p>';
echo '<hr size="1" />';
}
break;
}
?>

-------------

Also I need information on the best (just ok would work as well) method of setting up a "View Details" link in my results echo, pointing to the rest of the rows and the full description on a fresh page. How can you use "get" on your primary key if it can't be in the index that your search results are from? I can get all of the information I need using

echo $_GET['field1'];
echo $_GET['field2'];
echo $_GET['field3'];
echo $_GET['field4'];

...on the results page (results.php) as long as I link it in the search echo (search.php) as...

<a href="results.php?field1='.$row->name.'&field2'.$row->entry.'&field3'.$row->entry1.'&field4'.$row->entry2.'">

But then I have to put each .$row->entry. I want to $_GET in the link and cause my url to be 2 pages long when it generates because the description (a couple of paragraphs long) prints in the address bar. If it works, which technically it does, that's fine but it sure looks like it could screw something up.

So, in addition to the paging question, how can I just use my primary key even though it's not in the index, since the index is what is being searched? Or can I do something else to keep the url to a minimum but still display the contents of the single field? Just keep in mind the search results are what need to be linked, just like a "view details", "read more" or "more info" you'd see with most searches, leading to the single field.

Seems common enough, I just can't find any information on how to do this specifically.



Edited 2 time(s). Last edit at 10/13/2006 11:05AM by Lion .

Options: ReplyQuote


Subject
Views
Written By
Posted
HELP - Adding pagination and view details to this full-text search?
5001
October 11, 2006 10:00PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.