Hi, after 2 days of hard working i finally made my very first search script for my site. Im sure that it could be better, but to be my first one, i think its ok.
This scripts searches my MYSQL database (using Fulltext Search), it searches the fields 'item' (Item Name) and 'config_field_1' (Alternative names for the items). The problem is that in EVERY item the alternate name contains Japanese text (Kanji), and i cant make it to show the kanji propertly.
You can see it for your self here: http://www.animerate.net/buscador.php?cmd=search&mode=normal&words=seiya
As you can see, i get only HTML for that kanji (like 聖闘士星&#30690)
I changed the charset (from charset=iso-8859-1 to charset=utf-8) of my header file and didnts worked, i changed it also on the administration where i add the items (and write on text fields the Japanese alter names.) and didnt worked neither.
I dont know what else can i do, when i browse my items NOT USING the search script, i get the kanjis perfectly, the problems seems to be this new search script.
Here's the code:
// 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 '<center><form method="get" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="cmd" value="search" />';
echo '<input type="hidden" name="mode" value="normal" />';
echo '<span class=tbody> Buscar: <input type="text" name="words" value="'.$searchwords.'" /> </span>';
echo '<input type="submit" value="Buscar" />';
echo '</form></center>';
}
// Create the navigation switch
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');
switch($cmd)
{
default:
echo '<h1>Search Database!</h1>';
searchForm();
break;
case "search":
searchForm();
echo '<center><h3 class=tbody>Resultados de tu busqueda:</h3></center>';
$searchstring = mysql_escape_string($_GET['words']);
switch($_GET['mode'])
{
case "normal":
$sql = "SELECT *,
MATCH(item, config_field_1)
AGAINST ('$searchstring') AS score FROM mnl_items
WHERE MATCH(item, config_field_1)
AGAINST ('$searchstring') ORDER BY item DESC";
break;
case "boolean":
$sql = "SELECT item,
MATCH(item, config_field_1)
AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM mnl_items
WHERE MATCH(item, config_field_1)
AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
break;
}
// Header Table
echo "<table class=\"txtwhite\" bgcolor=\"white\" width=\"94%\" height=\"20\" align=\"center\" cellpadding=\"0\" cellspacing=\"1\" border=\"0\" class=\"tbodysmall\">\n";
echo "<tr>\n";
echo "<td width=\"70%\" class=\"txtwhite\" bgcolor=\"061376\"> Titulo</td>\n";
echo "<td align=\"center\" width=\"10%\" class=\"txtwhite\" bgcolor=\"061376\">Formato</td>\n";
echo "<td align=\"center\" width=\"10%\" class=\"txtwhite\" bgcolor=\"061376\">Episodios</td>\n";
echo "<td align=\"center\" width=\"10%\" class=\"txtwhite\" bgcolor=\"061376\">AƱo</td>\n";
echo "</tR>\n";
echo "</table>\n";
echo '<table border=0 align=center width=94% cellspacing=1 cellpadding=0>';
// echo $sql;
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_object($result))
{
$tempo ++;
if ($tempo / 2 == intval($tempo / 2 ))
{ $background = "#FFFFFF";}
else { $background = "#ECECEC";}
echo ' <tr bgcolor='.$background.' height=30>';
echo ' <td width=70% >';
echo ' <table width 100%>';
echo ' <tr><td class=biglinktextlist><img src=http://www.animerate.net/images/vineta3.gif align=\'absmiddle\'> <a href=review_list.php?item_id='.stripslashes(htmlspecialchars($row->item_id)).'&cat_id='.stripslashes(htmlspecialchars($row->cat_id)).'&sub_cat_id='.stripslashes(htmlspecialchars($row->sub_cat_id)).'><strong> '.stripslashes(htmlspecialchars($row->item)).'</strong></a></span></td></tr>';
echo ' <tr><td class=smalllinktextlist> <img src=http://www.animerate.net/images/vineta4.gif align=\'texttop\' width=17 height=9> <span class=smalllinktextlist>Titulos Alterno: <a href=review_list.php?item_id='.stripslashes(htmlspecialchars($row->item_id)).'&cat_id='.stripslashes(htmlspecialchars($row->cat_id)).'&sub_cat_id='.stripslashes(htmlspecialchars($row->sub_cat_id)).'>'.stripslashes(htmlspecialchars($row->config_field_1)).'</a></span></td></tr>';
echo ' </table>';
echo ' </td>';
echo ' <td width=10% align=center class=top100>'.stripslashes(htmlspecialchars($row->config_field_5)).'</td>';
echo ' <td width=10% align=center class=top100>'.stripslashes(htmlspecialchars($row->config_field_6)).'</td>';
echo ' <td width=10% align=center class=top100>'.stripslashes(htmlspecialchars($row->config_field_7)).'</td>';
echo ' </tr>';
}
break;
}
echo ' </table>';
I hope you can help me on this.