Hi,
I got a little bit problem about search result in my site. When i put the keyword and click on search ....everything work fine i got the correct result but they not order by the keyword,but they order by the alphabet.....some and the problem is happen sure if there are many result to display...the real result that people put keyword for will be in the last page...because the computer order by the alphabet.
for example...i put the keyword IN
The search result display .... Anin Chinmai Intel .....instead of order by what people search for..
How can i set up this?
Thank you so much sir.
Paitoon
12 2955
Heya, Paitoon.
What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
You are after relevance searching, which is no simple task. You must first decided exactly *what* counts as more relevant to the user than something else, then exactly *how* relevant it should be, and finally how to *calculate* that relevance.
You should get your search results, send them through your relevance algorithm, sort the data, and then save / display it.
I still cunfuse with this......but i can give you the example:
i want to find the people who have the name start with I so i put the key word i and click to search.....then the search result come with the word which have i in side....for example Adipong Adichart Bird Chinmai Diorgirl
but they not order by what i search for.It order by a b c d e f g........
Seem like the search knows that i want to find people who have name i in their name but it dont order it by i ..in the opposite way it order by a b c d e
f......
I see from google or facebook when i put key word and click search ...it will show the word which begin with the keyword i search for...
but in my site the search will find the name which have the keyword that i search for but not order with that key word but it order by a b c d e f g.........
so stress :-/
Paitoon
Heya, Paitoon.
So what you're saying is that you want results that start with your keyword to show up before results that merely contain your keyword. Is that correct?
What version of MySQL are you running?
I use php 5.2.2 ,But i dont know hwat is that version..
Yes you are right....that is my really problem.....
thank you so much...i willl try...:-)
Hi...
Could you please post the code you are using? I recently rewrote the code for the search page on one of my websites, and I might be able to help you with yours if I were able to have a look at the code you are using.
Staria
The c is here..... -
<?
-
$q=$_GET[q];
-
$page=$_GET[page];
-
if ($page=="") {
-
$page=1;
-
}
-
$each=20; // specify number of image per one page//
-
?>
-
-
<table border="0" cellpadding="0" cellspacing="0">
-
<td ><form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>" >
-
<table bgcolor="#F8F8F8" class="ExtraSearch">
-
<td>
-
<input name="q" type="text" value="<?php echo $q; ?>" size="25" />
-
<input name="submit" type="submit" id="BlueFormbtn" value="Search" />
-
</table>
-
</form></td>
-
</table>
-
<?php
-
//This is a working script
-
//Make sure to go through it and edit database table filelds that you are seraching
-
//This script assumes you are searching 3 fields
-
-
$hostname_logon = "" ;
-
$database_logon = "" ;
-
$username_logon = "" ;
-
$password_logon = "" ;
-
//open database connection
-
$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" );
-
//select database
-
mysql_select_db($database_logon) or die ( "Unable to select database!" );
-
-
-
// Get the search variable from URL
-
$var = @$_GET['q'] ;
-
//trim whitespace from the stored variable
-
$trimmed = trim($var);
-
//separate key-phrases into keywords
-
$trimmed_array = explode(" ",$trimmed);
-
-
// check for an empty string and display a message.
-
if ($trimmed == "") {
-
$resultmsg = "<center><p>Search Error</p><p>Please enter a search...</p></center><br><br>" ;
-
}
-
-
// Build SQL Query for each keyword entered
-
foreach ($trimmed_array as $trimm){
-
-
// EDIT HERE and specify your table and field names for the SQL query
-
$query = "SELECT * FROM users WHERE username LIKE \"%$trimm%\" ORDER BY username DESC" ;
-
// Execute the query to get number of rows that contain search kewords
-
$numresults=mysql_query ($query);
-
$row_num_links_main =mysql_num_rows ($numresults);
-
-
-
$adid_array[] = $row[ 'fieldid' ];
-
}while( $row= mysql_fetch_array($numresults));
-
//end foreach
-
-
if($row_num_links_main == 0 && $row_set_num == 0){
-
$resultmsg = "<center><p>Search results for:" . $trimmed ."</p><p>Sorry, your search returned zero results</p></center><BR><br>" ;
-
}
-
//delete duplicate record id's from the array. To do this we will use array_unique function
-
$tmparr = array_unique($adid_array);
-
$i=0;
-
foreach ($tmparr as $v) {
-
$newarr[$i] = $v;
-
$i++;
-
}
-
-
// now you can display the results returned. But first we will display the search form on the top of the page
-
?>
-
<?php
-
include "provincelist.php";
-
// display what the person searched for.
-
if( isset ($resultmsg)){
-
echo $resultmsg;
-
exit();
-
}else{
-
-
foreach($newarr as $value){
-
-
// EDIT HERE and specify your table and field names for the SQL query
-
$query_value = "SELECT * FROM users WHERE username = '$value'";
-
$num_value=mysql_query ($query_value);
-
$row_linkcat= mysql_fetch_array ($num_value);
-
$row_num_links= mysql_num_rows ($num_value);
-
-
//now let's make the keywods bold. To do that we will use preg_replace function.
-
//EDIT parts of the lines below that have fields names like $row_linkcat[ 'field1' ]
-
//This script assumes you are searching only 3 fields. If you are searching more fileds make sure that add appropriate line.
-
$titlehigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'username' ] );
-
foreach($trimmed_array as $trimm){
-
-
//end highlight
-
$connections="select * from users where username like'%$trimm%'";
-
$result=mysql_db_query($database_logon,$connections);
-
$total=mysql_num_rows($result);
-
$totalpages=ceil($total/$each);
-
$goto = ($page-1)*$each;
-
-
$connections="select * from users where username like'%$trimm%' order by username limit $goto,$each";
-
$result=mysql_db_query($database_logon,$connections);
-
$num=mysql_num_rows($result);
-
-
while($rs=mysql_fetch_array($result)) {
-
$username=$rs[username];
-
$password=$rs[password];
-
$userid=$rs[userid];
-
$userlevel=$rs[userlevel];
-
$email=$rs[email];
-
$timestamp=$rs[timestamp];
-
$photo=$rs[photo];
-
$sex=$rs[sex];
-
$province=$rs[province];
-
$aboutme=$rs[aboutme];
-
$vote=$rs[vote];
-
$lookfor=$rs[lookfor];
-
$figure=$rs[figure];
-
-
echo "<table width=\"580\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" align=\"center\" id='search_page'><tr>";
-
if ($photo=="") {
-
echo "<td ><IMG SRC='site_img/nophoto.gif' width='95' height='95' border='1'/></td>";
-
}else {
-
echo"<td><a href='#' onclick=\"displayStaticMessage('<img src=prof_photo/$photo width=400 height=400/> <a href=\'#\' onclick=\'closeMessage();return false\'><img src=c.gif /></a>','modalDialog_contentDiv_error');return false\">
-
<IMG SRC=\"prof_photo/$photo\" width=\"95\" height=\"95\" BORDER=\"1\" ></A></td>";}
-
echo"<td><div id='searchDivUserName'>username : <a href=\"seeprof.php?id=$username\"> $username </a><br>";
-
if ($sex=="M") {
-
echo "เพศ : ชาย<br>";
-
} else if ($sex=="W") {
-
echo "เพศ : หญิง<br>";
-
} else if($sex=="G") {
-
echo "เพศ : เกย์<br>";
-
} else if ($sex=="T") {
-
echo "เพศ : ทอม<br>";
-
} else if($sex=="D") {
-
echo "เพศ : ดี้<br>";
-
} else if($sex=="B") {
-
echo "เพศ : Bisexual<br>";
-
}
-
echo"จังหวัด : $p[$province]
-
</div></td>";
-
echo" <td ><div id='searchDivLink'>
-
<a href ='seeprof.php?id=$username'>ดูโปรไฟล์</a>
-
<a href ='sendmail.php?id=$username'>ส่งอีเมลย์</a>
-
-
-
</div></td>
-
</tr>
-
</table><tr>";
-
-
-
}
-
-
}
-
-
}
-
}
-
-
?><br />
-
<br />
-
</div>
-
<div id="imgpage">
-
<?
-
-
if ($totalpages>1) {
-
echo "<B>หน้า $page</B><BR>";
-
for ($i=1;$i<=$totalpages;$i++) {
-
echo "| <A HREF='search_name.php?q=$q&submit=Search&page=$i'>$i</A> ";
-
}
-
}
-
?>
-
</div>
-
<br />
-
<br />
-
</div>
-
</div>
-
</div>
-
</div>
-
<br />
-
<div id="footer">
-
</div>
-
</div>
-
</div>
-
</body>
-
</html>
Heya, Alex.
Please use CODE tags when posting source code:
[CODE=php]
PHP code goes here.
[/CODE]
Oh Im sorry sir. I will remember now.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Powell |
last post by:
The table already has a fulltext index and from there I can use the
MySQL fulltext search query to get results as well as the relevancy
score.
The problem I have is that MySQL has a default...
|
by: Stefan Krah |
last post by:
Hello,
I am currently writing code where it is convenient to convert
char to int . The conversion function relies on
a character set with contiguous alphabets.
int set_mesg(Key *key, char...
|
by: Jack Addington |
last post by:
I want to scroll through the alphabet in order to scroll some data to the
closest name that starts with a letter. If the user hits the H button then
it should scroll to the letter closest to H. ...
|
by: chadsmith76 |
last post by:
hello,
I have listings with coordinates, i would like to do ORDER BY and
display listings with coords first. If they don't have coords the value
is blank and the coords go both positive and...
|
by: Kwok |
last post by:
I want to search a keyword in a content stored in a table, which the content is a abstract of a report
I want to search a keyword by exact word such as:
User input : news report
The result will...
|
by: bb nicole |
last post by:
Below is my search engine for job portal which jobseeker can find the job through quick search. But it cant work... Is it mysql query got problem?? Thanx..
Interface
<html>
<head>
<title>UMS...
|
by: Laser Lu |
last post by:
Sometimes, I need to do some time-consuming operations based on whether a
specific keyword was contained in a lengthy string. Then, for a better
performance, I wrapped that lengthy string into a...
|
by: Moezzie |
last post by:
Im going totally crazy over this.
Im right now building a verry small solution for searching a mysql-database for up to five keywords.
Every file in the database has 2 or more keywords wich the...
|
by: adelemb |
last post by:
Hi,
I'm trying to make a SQL statement work and am getting quite mixed up with it, I hope someone can help!
I have a form with a textbox named "keyword". I want the user to enter a keyword and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |