MySQL търсене - ГОЛЯМ ПРОБЛЕМ

3 отговора 155 прегледа
#1

MySQL търсене - ГОЛЯМ ПРОБЛЕМ

Инсталирал съм една CMS система. Когато от администраторският панел търся статии по определена дума, те си излизат без проблем в резултатите. Просто е перфекто - търси в заглавията в телата на статиите и т.н.

НО, когато от потребителският край търся статии използвайки дума съдържаща се в тях, НОМЕРА не става......

Дори при показване на резултатите не показва самата търсена дума ( вместо търсенето на "примерни_думи" , ми излиза само "" )

търсенето в БД от админската и потребителската страна става с различни файлове, това е админският файл, правещ търсенето в БД

<?php


function storysearch() {

global $HTTP_SESSION_VARS;

$user = $HTTP_SESSION_VARS["user"];

eval(loadlib("forms"));

eval(form_fields_to_local("module,function,op,sort_column,sort_direction"));
eval(form_fields_to_local("include_criteria"));
eval(form_fields_to_local("headline,subhead,body_content,thread,min_age,max_age"));
eval(form_fields_to_local("byline_name,workflow_status_id,publication_status_id"));
eval(form_fields_to_local("created_by,modified_by,assigned_to,assigned_by,section_id,edition_id"));
eval(form_fields_to_local("origination,copyright,quicksearch_name"));

define("MAX_RESULTS_PER_PAGE", "75");


eval(loadlib("sections"));

// Trap form submissions here
switch($op) {

case "Do search": {

// Set default sort_column and direction
if (rtrim($sort_column) == "")
$sort_column = "modified_stamp";

if (rtrim($sort_direction) == "")
$sort_direction = "DESC";

// If user didn't select any criteria..
if (!isset($include_criteria))
$ErrorMessage = "You didn't select any criteria to search on.";

// If all is well, do the search, otherwise drop through and display
// error
if (!$ErrorMessage) {

// Assemble SQL
$q = "SELECT props_stories.story_id, headline, published_stamp, modified_stamp, ";
$q .= "assigned_to, assigned_by, workflow_status_id, publication_status_id, section_id ";
$q .= " FROM props_stories LEFT JOIN props_edition_story_xref ON ";
$q .= "(props_stories.story_id = props_edition_story_xref.story_id) WHERE (1=1) ";

// Add text fields to query string
$text_search_fields = array(
"headline",
"subhead",
"body_content"
);

foreach($text_search_fields as $fieldname) {

// if this criteria is checked
if (in_array($fieldname, $include_criteria)) {

// add it to the query
eval("\$matchvalue = \$$fieldname;");
$q .= " AND $fieldname LIKE '%$matchvalue%' ";
}
}

// Add numeric fields to query string
$numeric_search_fields = array(
"edition_id"
);

foreach($numeric_search_fields as $fieldname) {

// if this criteria is checked
if (in_array($fieldname, $include_criteria)) {

// add it to the query
eval("\$matchvalue = \$$fieldname;");
$q .= " AND $fieldname = $matchvalue ";
}
}

// Add selectbox fields to query string
$listbox_search_fields = array(
"byline_name",
"publication_status_id",
"workflow_status_id",
"created_by",
"modified_by",
"assigned_to",
"assigned_by",
"section_id",
"origination",
"copyright"
);

foreach($listbox_search_fields as $fieldname) {

// if this criteria is checked
if (in_array($fieldname, $include_criteria)) {

// Loop through all selected values and add them
// to the query
eval("
\$itemcount = 0;
if (isset(\$$fieldname)) {
\$q .= \" AND (\";
foreach(\$$fieldname as \$item) {
\$q .= \"$fieldname = '\$item' \";
if (++\$itemcount < sizeof(\$$fieldname))
\$q .= \" OR \";
}
\$q .= \")\";
}");
}
}

// Some fields are custom, and need to be added to the SQL query
// on an individual basis.
if (in_array("min_age", $include_criteria))
$q .= "AND DATE_SUB(NOW(), INTERVAL $min_age DAY) >= created_stamp ";

if (in_array("max_age", $include_criteria))
$q .= "AND DATE_SUB(NOW(), INTERVAL $max_age DAY) <= created_stamp ";

if (in_array("thread", $include_criteria))
$q .= "AND thread = '" . strtoupper(trim($thread)) . "' ";

$q .= " GROUP BY story_id";
$q .= " ORDER BY $sort_column $sort_direction";

// Execute query
$search_query = sql_query($q);

// If user specified a quicksearch name, save
// this searches parameters in the quicksearch bar
if ((rtrim($quicksearch_name) != "") && ($dont_resave != "true")){

// first delete any of this user's quicksearches which have the same name
sql_query("DELETE FROM props_administrator_quicksearches WHERE login='" . $_SESSION["user"]->login . "' AND admin_quicksearch_name = '$quicksearch_name'");

// Now get the URI for this search and insert the search we just did
$uri = search_results_uri();
sql_query("INSERT INTO props_administrator_quicksearches(login, admin_quicksearch_name, admin_quicksearch_uri) VALUES('" . $_SESSION["user"]->login . "', '$quicksearch_name', '$uri')");
}

// Now reverse sort direction, so that clicking on the same column
// will reverse the list
if ($sort_direction == "ASC")
$sort_direction = "DESC";
else
$sort_direction = "ASC";

// Display results
if (rtrim($quicksearch_name) != "")
$pagetitle .= "'$quicksearch_name' quicksearch results";
else
$pagetitle = "Search results";

include_once("admin_header.php");
output_search_results($search_query, $sort_direction);

include_once("admin_footer.php");
exit;
}
} break;

case "Delete quicksearch": {

sql_query("DELETE FROM props_administrator_quicksearches WHERE login='" . $_SESSION["user"]->login . "' AND admin_quicksearch_name = '$quicksearch_name'");
header("Location: " . get_config_param("base_admin_url") . "index.php?module=adminmainmenu&function=mainmenu");
exit;
} break;
}

$pagetitle = "Search for a story";
include_once("admin_header.php");

if (!isset($include_criteria))
$include_criteria = array();

?>
<p align="center">Find stories matching all of the following criteria:</p>
<div align="center">
<form action="index.php" method="get">
<input name="module" value="<?php echo $module; ?>" type="hidden">
<input name="function" value="<?php echo $function; ?>" type="hidden">
<table border="0">

<!-- headline -->
<?php if (in_array("headline", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="headline"> Headline contains: </p></td>
<td valign="middle">
<input name="headline" value="<?php echo $headline;?>" type="text" size="36" maxlength="128">
</td>
</tr>

<!-- subhead -->
<?php if (in_array("subhead", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="subhead"> Subhead contains: </p></td>
<td valign="middle">
<input name="subhead" value="<?php echo $subhead;?>" type="text" size="36" maxlength="128">
</td>
</tr>

<!-- body_content -->
<?php if (in_array("body_content", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="body_content"> Body content contains: </p></td>
<td valign="middle">
<input name="body_content" value="<?php echo $body_content;?>" type="text" size="36" maxlength="128">
</td>
</tr>

<script type="text/javascript">
function toupper(o){
o.value=o.value.toUpperCase().replace(/([^0-9A-Z])/g,"");
}
</script>

<!-- thread -->
<?php if (in_array("thread", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="thread"> Thread code is: </p></td>
<td valign="middle">
<input name="thread" value="<?php echo $thread;?>" type="text" size="25" maxlength="25" onkeydown="toupper(this)" onkeyup="toupper(this)" onblur="toupper(this)" onclick="f(this)">
</td>
</tr>

<!-- min_age -->
<?php if (in_array("min_age", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="min_age"> Creation date is at least: </p></td>
<td valign="middle">
<input name="min_age" value="<?php echo $min_age;?>" type="text" size="4" maxlength="6"> days ago
</td>
</tr>

<!-- max_age -->
<?php if (in_array("max_age", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="max_age"> Creation date is no more than: </p></td>
<td valign="middle">
<input name="max_age" value="<?php echo $max_age;?>" type="text" size="4" maxlength="6"> days ago
</td>
</tr>

<!-- byline -->
<?php if (in_array("byline_name", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="byline_name"> Byline name is: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT Distinct(rtrim(byline_name)) AS byline_name FROM props_stories ORDER BY byline_name");
listbox($query, "byline_name", "byline_name", 3);
?>
</td>
</tr>

<!-- publication_status_id -->
<?php
if (!isset($publication_status_id))
$publication_status_id = array();

if (in_array("publication_status_id", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="publication_status_id"> Publication status is: </p></td>
<td valign="middle">
<select multiple name="publication_status_id[]" size="3">
<option <?php if (in_array(PUBSTATUS_INEDITQUEUE, $publication_status_id)) echo "selected "; ?>value="<?php echo PUBSTATUS_INEDITQUEUE; ?>">In Edit Queue</option>
<option <?php if (in_array(PUBSTATUS_STAGED, $publication_status_id)) echo "selected "; ?>value="<?php echo PUBSTATUS_STAGED; ?>">Staged for Publication</option>
<option <?php if (in_array(PUBSTATUS_PUBLISHED, $publication_status_id)) echo "selected "; ?>value="<?php echo PUBSTATUS_PUBLISHED; ?>">Published</option>
<option <?php if (in_array(PUBSTATUS_ARCHIVED, $publication_status_id)) echo "selected "; ?>value="<?php echo PUBSTATUS_ARCHIVED; ?>">Archived</option>
</select>
</td>
</tr>

<!-- workflow_status_id -->
<?php if (in_array("workflow_status_id", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="workflow_status_id"> Workflow status is: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT * FROM props_workflow_status ORDER BY rank");
listbox($query, "workflow_status_id", "workflow_status_name", 3);
?>
</td>
</tr>

<!-- created by -->
<?php if (in_array("created_by", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="created_by"> Created by: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT fullname, login AS created_by FROM props_administrators ORDER BY fullname");
listbox($query, "created_by", "fullname", 3);
?>
</td>
</tr>

<!-- last_modified_by -->
<?php if (in_array("modified_by", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="modified_by"> Last modified by: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT fullname, login AS modified_by FROM props_administrators ORDER BY fullname");
listbox($query, "modified_by", "fullname", 3);
?>
</td>
</tr>

<!-- assigned_to -->
<?php if (in_array("assigned_to", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="assigned_to"> Assigned to: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT fullname, login AS assigned_to FROM props_administrators ORDER BY fullname");
listbox($query, "assigned_to", "fullname", 3);
?>
</td>
</tr>

<!-- assigned_by -->
<?php if (in_array("assigned_by", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="assigned_by"> Assigned by: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT fullname, login AS assigned_by FROM props_administrators ORDER BY fullname");
listbox($query, "assigned_by", "fullname", 3);
?>
</td>
</tr>

<!-- section -->
<?php if (in_array("section_id", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="section_id"> Section is: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT section_id, fullname FROM props_sections");
listbox($query, "section_id", "fullname", 3);
?>
</td>
</tr>

<!-- origination -->
<?php if (in_array("origination", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="origination"> Origination is: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT Distinct(origination) FROM props_stories ORDER BY origination");
listbox($query, "origination", "origination", 3);
?>
</td>
</tr>

<!-- copyright -->
<?php if (in_array("copyright", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="copyright"> Copyright is: </p></td>
<td valign="middle">
<?php
$query = sql_query("SELECT Distinct(copyright) FROM props_stories ORDER BY copyright");
listbox($query, "copyright", "copyright", 3);
?>
</td>
</tr>

<!-- appears in edition -->
<?php if (in_array("edition_id", $include_criteria)) $checked_string = " checked"; else $checked_string = ""; ?>
<tr>
<td valign="middle"><p><input<?php echo $checked_string; ?> type="checkbox" name="include_criteria[]" value="edition_id"> Appears in edition no.: </p></td>
<td valign="middle">
<input name="edition_id" value="<?php echo $edition_id;?>" type="text" size="4" maxlength="6">
</td>
</tr>

<!-- save search as -->
<tr>
<td valign="middle"><p>Save in quicksearch menu as: </p></td>
<td valign="middle">
<input name="quicksearch_name" value="<?php echo $quicksearch_name; ?>" size="30" maxlength="30">
</td>
</tr>

</table>


<?php if ((rtrim($quicksearch) == "") && ($op == "Modify search")) { ?>
<input name="op" value="Delete quicksearch" type="submit">
<?php } ?>
<input name="op" value="Do search" type="submit">
</form>
</div>

<?php
include_once("admin_footer.php");
}

// This generates the listboxes on the search form
function listbox($query, $value_column, $display_column, $size) {

echo "<select name=\"$value_column" . "[]" . "\" multiple size=\"$size\">";

eval("form_fields_to_local(\"\$$value_column\");");

while ($row = sql_fetch_object($query)) {

eval("\$value = \$row->$value_column;");
eval("\$display = \$row->$display_column;");

$selected_string = ""; //default to unselected

eval(form_fields_to_local("$value_column"));
eval("if (isset(\$$value_column)) {
if (in_array('$value', \$$value_column))
\$selected_string = \" selected\";
}");

echo "<option$selected_string value=\"$value\">$display</option>\n";
}

echo "</select>";
}


// given a handle to a query on the stories table, outputs a table
// listing results of the query
function output_search_results($query, $sort_direction) {

eval(form_fields_to_local("quicksearch_name,sort_column,ErrorMessage"));

if (sql_num_rows($query)) {
?>
<div align="center">


<?php
if (sql_num_rows($query) == 1)
echo "<p align=\"center\">1 story found</p>";
elseif (sql_num_rows($query) <= MAX_RESULTS_PER_PAGE)
echo "<p align=\"center\">" . sql_num_rows($query) . " stories found</p>";
else
echo "<p align=\"center\" style=\"color:red\">Listing has been truncated. Only displaying the first " . MAX_RESULTS_PER_PAGE . " out of " . sql_num_rows($query) . " stories found.</p>";

echo "<table class=\"hairline\">";


// Populate lookup array with all the workflow statuses
$workflow_status = array();
$stat_query = sql_query("SELECT * FROM props_workflow_status ORDER BY rank");
while ($srow = sql_fetch_object($stat_query))
$workflow_status[$srow->workflow_status_id] = $srow->workflow_status_name;

// Populate lookup array with all the publication statuses
$publication_status = array();
$publication_status[PUBSTATUS_INEDITQUEUE] = "In Edit Queue";
$publication_status[PUBSTATUS_STAGED] = "Staged for Publication";
$publication_status[PUBSTATUS_PUBLISHED] = "Published";
$publication_status[PUBSTATUS_ARCHIVED] = "Archived";

// Output table
?>
<!-- header row -->
<tr bgcolor="#cccccc">
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() . "&sort_column=headline&sort_direction=$sort_direction"; ?>">Headline</a></p></th>
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() ."&sort_column=section_id&sort_direction=$sort_direction"; ?>">Section</a></p></th>
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() ."&sort_column=published_stamp&sort_direction=$sort_direction"; ?>">Published</a></p></th>
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() ."&sort_column=assigned_to&sort_direction=$sort_direction"; ?>">Assigned to</a></p></th>
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() ."&sort_column=assigned_by&sort_direction=$sort_direction"; ?>">Assigned by</a></p></th>
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() ."&sort_column=workflow_status_id&sort_direction=$sort_direction"; ?>">Workflow status</a></p></th>
<th><p class="search_results"><a href="<?php echo preg_replace("/\/$/", "", get_config_param("base_admin_url")) . search_results_uri() ."&sort_column=publication_status_id&sort_direction=$sort_direction"; ?>">Publication status</a></p></th>
<th><p></p></th>
</tr>
<?php

$numresults = 0;
while (($row = sql_fetch_object($query)) && (++$numresults <= MAX_RESULTS_PER_PAGE)) {

$headline_string = $row->headline;
if (strlen($headline_string) > 35)
$headline_string = substr($headline_string, 0, 35) . "...";

?>
<tr bgcolor="#ffffff">
<td align="left"><p class="search_results"><?php echo "<a href=\"index.php?module=adminstories&function=view_story&story_id=$row->story_id\">$headline_string</a>"; ?></p></td>
<td align="center"><p class="search_results"><?php echo section_shortname($row->section_id); ?></p></td>
<td align="center"><p class="search_results"><?php if (($row->publication_status_id == PUBSTATUS_PUBLISHED) || ($row->publication_status_id == PUBSTATUS_ARCHIVED)) echo date("d M y", strtotime($row->published_stamp)); ?></p></td>
<td align="center"><p class="search_results"><?php echo $row->assigned_to; ?></p></td>
<td align="center"><p class="search_results"><?php echo $row->assigned_by; ?></p></td>
<td align="center"><p class="search_results"><?php echo $workflow_status[$row->workflow_status_id]; ?></p></td>
<td align="center"><p class="search_results"><?php echo $publication_status[$row->publication_status_id]; ?></p></td>
<td align="center"><p class="search_results"><a href="<?php echo get_config_param("base_admin_url") . "index.php?module=adminstories&function=delete_story&story_id=$row->story_id"; ?>"><img src="images/delete.gif" width="10" height="11" border="0" /></a></td>
</tr>
<?php
}

echo "</table>";
} else
echo "<p align=\"center\">No stories found.</p>";
?>
<!-- modify search button -->


<form action="index.php" method="get">
<input name="module" value="adminsearch" type="hidden">
<input name="function" value="storysearch" type="hidden">
<div align="center">
<input name="op" value="Modify search" type="submit">
</div>

<?php
// output hidden fields with all the search parameters

// output single value form fields
$single_field_names = array(
"headline",
"subhead",
"body_content",
"quicksearch_name",
"edition_id",
"min_age",
"max_age",
"thread"
);

foreach($single_field_names as $field_name) {
eval(form_fields_to_local("$field_name"));
// eval("global \$$field_name;");
eval("\$field_value = \$$field_name;");
echo "<input name=\"$field_name\" value=\"$field_value\" type=\"hidden\">\n";
}

// output multiple value (array) form fields (i.e. listboxes)
$array_field_names = array(
"include_criteria",
"byline_name",
"publication_status_id",
"workflow_status_id",
"created_by",
"modified_by",
"assigned_to",
"assigned_by",
"section_shortname",
"origination",
"copyright"
);

foreach($array_field_names as $field_name) {

eval(form_fields_to_local("$field_name"));
// eval("global \$$field_name;");
eval("
if (isset(\$$field_name)) {
foreach(\$$field_name as \$value) {
echo '<input name=\"$field_name' . \"[]\" . '\" value=\"' . \$value . '\" type=\"hidden\">\n';
}
}
");
}


?>
</form>
</div>
<?php
}


// Returns a URI pointing to the current search
function search_results_uri() {

$uri = "/?module=adminsearch&function=storysearch&op=Do+search&dont_resave=true";

$single_field_names = array(
"headline",
"subhead",
"body_content",
"quicksearch_name",
"edition_id",
"min_age",
"max_age",
"thread"
);

foreach($single_field_names as $field_name) {
eval(form_fields_to_local("$field_name"));
// eval("global \$$field_name;");
eval("\$field_value = \$$field_name;");
$uri .= "&$field_name=" . urlencode($field_value);
}

// output multiple value (array) form fields (i.e. listboxes)
$array_field_names = array(
"include_criteria",
"byline_name",
"publication_status_id",
"workflow_status_id",
"created_by",
"modified_by",
"assigned_to",
"assigned_by",
"section_id",
"origination",
"copyright"
);

foreach($array_field_names as $field_name) {

// eval("global \$$field_name;");
eval(form_fields_to_local("$field_name"));
eval("
if (isset(\$$field_name)) {
foreach(\$$field_name as \$value) {
if (trim(\$value) != \"\")
\$uri .= \"&\$field_name\" . \"[]\" . \"=\" . urlencode(\$value);
}
}
");
}

return $uri;
}

?>


този е от потребителска страна

<?php


function do_search() {

// Populate glossary with info about the search. Sanitize all URL variables.
glossary_set("start", intval(get_form_field("start"))); // force to int value
glossary_set("archives_daterange_selected", get_form_field("date_range"));
glossary_set("archives_sortorder_selected", get_form_field("archives_sortorder"));

$search_string = get_form_field("search_string");
$search_string = ereg_replace("[^- _a-zA-Z0-9.,:/]", "", $search_string); // Sanitize
$search_string = addslashes($search_string);
glossary_set("search_string", $search_string);

// Determine type of date range restriction, if any
list($date_range_type, $date_range_value) = split(' ', get_form_field("date_range"));
$date_range_type = ereg_replace("[^A-Z]", "", $date_range_type); // Sanitize URL input
$date_range_value = intval($date_range_value); // Sanitize URL input

// Set the results order based upon the user's selection
if (glossary_get("archives_sortorder_selected") == "most_recent")
$sql_order = "published_stamp DESC, score DESC";
else
$sql_order = "score DESC, published_stamp DESC";

// If there were no errors, assemble an SQL query to return a list
// of matching story_id's, then run that query
if (!glossary_get("error_message")) {

$q = "SELECT story_id, ";
$q .= "((MATCH (headline) AGAINST ('$search_string'))*5 + ";
$q .= " (MATCH (body_content) AGAINST ('$search_string'))*2 + ";
$q .= " (MATCH (end_content) AGAINST ('$search_string')) ) AS score ";
$q .= "FROM props_stories ";
$q .= "WHERE publication_status_id IN (" . PUBSTATUS_ARCHIVED . "," . PUBSTATUS_PUBLISHED . ") ";
$q .= "AND (MATCH (headline) AGAINST ('$search_string') ";
$q .= "OR MATCH (body_content) AGAINST ('$search_string') ";
$q .= "OR MATCH (end_content) AGAINST ('$search_string')) ";
if ($date_range_type == "R")
$q .= " AND DATE_SUB(NOW(), INTERVAL $date_range_value DAY) <= published_stamp ";
elseif ($date_range_type == "Y")
$q .= " AND YEAR(published_stamp) = '$date_range_value' ";
$q .= "ORDER BY $sql_order ";
$q .= "LIMIT 199";
$query_handle = sql_query($q);

glossary_set("query_handle", $query_handle);

// Set more results properties
glossary_set("num_results", sql_num_rows(glossary_get("query_handle")));
glossary_set("stories_per_page", 10);

glossary_set("current_page", (1 +
(glossary_get("start") / glossary_get("stories_per_page"))));

glossary_set("num_pages", intval(1 +
(glossary_get("num_results") / glossary_get("stories_per_page"))));

// Set the "alternate template suffix"
// to force the interpreter to load
// the archive-searchresults template instead of the usual archives
// template. The tags within the template will handle the
// presentation of the results.
glossary_set("alternate_template_suffix", "searchresults");

// if this is the very first page of results, log the search
if (glossary_get("current_page") == 1) {
$keywords = explode(" ", $search_string);
log_search($search_string, $keywords);
}
}

}


?>


Отговор
в отговор на Cимeoн #2

Re: MySQL търсене - ГОЛЯМ ПРОБЛЕМ

Има си клуб за бази от данни!

Отговор
в отговор на Cимeoн #3

Re: MySQL търсене - ГОЛЯМ ПРОБЛЕМ

Някой може ли да ми обясни защо този човек е използвал готов скрипт?

Отговор
в отговор на Cимeoн #4

ГОЛЯМ ПРОБЛЕМ???

В отговор на:


Инсталирал съм една CMS система.




И защо си мислиш, че тук е support-а на CMS (която ако бе казал коя е, някой неин фен би могло и да ти отговори). Най-добре е да потърсиш на сайта на CMS - най-вероятно е много преди теб да са питали това и да са отговорили. И не е нужно да публикуваш половината код на нещо което го има в Интернет. Който проявиинтерес ще си го дръпне, разгледа и ще ти отговори...

Отговор