473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to order the alphabet in search result order by the keyword ?

62
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
Sep 8 '07 #1
12 2955
pbmods
5,821 Expert 4TB
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.
Sep 9 '07 #2
kovik
1,044 Expert 1GB
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.
Sep 9 '07 #3
paitoon
62
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
Sep 9 '07 #4
pbmods
5,821 Expert 4TB
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?
Sep 9 '07 #5
paitoon
62
I use php 5.2.2 ,But i dont know hwat is that version..
Sep 9 '07 #6
paitoon
62
Yes you are right....that is my really problem.....
Sep 9 '07 #7
pbmods
5,821 Expert 4TB
Heya, Paitoon.

You might want to look into working with fulltext searching.
Sep 9 '07 #8
paitoon
62
thank you so much...i willl try...:-)
Sep 9 '07 #9
Staria
7
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
Sep 9 '07 #10
paitoon
62
The c is here.....
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $q=$_GET[q];
  3. $page=$_GET[page];
  4. if ($page=="") {
  5.         $page=1;
  6. }
  7. $each=20; // specify number of image per one page//
  8. ?>
  9.  
  10.           &nbsp;&nbsp;<table border="0" cellpadding="0" cellspacing="0">
  11.   <td ><form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>" >
  12.     <table bgcolor="#F8F8F8" class="ExtraSearch">
  13.         <td>
  14.                 <input name="q" type="text" value="<?php echo $q; ?>" size="25" />
  15.                 <input name="submit" type="submit" id="BlueFormbtn" value="Search" />
  16.         </table>
  17.   </form></td>
  18.     </table>
  19.             <?php 
  20. //This is a working script
  21. //Make sure to go through it and edit database table filelds that you are seraching
  22. //This script assumes you are searching 3 fields
  23.  
  24. $hostname_logon = "" ;   
  25. $database_logon = "" ;  
  26. $username_logon = "" ;  
  27. $password_logon = "" ;   
  28. //open database connection
  29.  $connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" );
  30.  //select database
  31.  mysql_select_db($database_logon) or die ( "Unable to select database!" );
  32.  
  33.  
  34. // Get the search variable from URL
  35.   $var = @$_GET['q'] ;
  36. //trim whitespace from the stored variable
  37.   $trimmed = trim($var);  
  38. //separate key-phrases into keywords
  39.   $trimmed_array = explode(" ",$trimmed); 
  40.  
  41. // check for an empty string and display a message.
  42. if ($trimmed == "") {
  43.   $resultmsg =  "<center><p>Search Error</p><p>Please enter a search...</p></center><br><br>" ;
  44.   }
  45.  
  46. // Build SQL Query for each keyword entered 
  47. foreach ($trimmed_array as $trimm){
  48.  
  49. // EDIT HERE and specify your table and field names for the SQL query
  50.      $query = "SELECT * FROM users WHERE username LIKE \"%$trimm%\"  ORDER BY username   DESC" ; 
  51.      // Execute the query to  get number of rows that contain search kewords
  52.      $numresults=mysql_query ($query);
  53.      $row_num_links_main =mysql_num_rows ($numresults);
  54.  
  55.  
  56.        $adid_array[] = $row[ 'fieldid' ];
  57.       }while( $row= mysql_fetch_array($numresults));
  58. //end foreach
  59.  
  60. if($row_num_links_main == 0 && $row_set_num == 0){
  61.    $resultmsg = "<center><p>Search results for:" . $trimmed  ."</p><p>Sorry, your search returned zero results</p></center><BR><br>" ;
  62. }
  63.    //delete duplicate record id's from the array. To do this we will use array_unique function
  64.    $tmparr = array_unique($adid_array); 
  65.    $i=0; 
  66.    foreach ($tmparr as $v) { 
  67.        $newarr[$i] = $v; 
  68.        $i++; 
  69.    } 
  70.  
  71. // now you can display the results returned. But first we will display the search form on the top of the page
  72. ?>
  73.             <?php
  74. include "provincelist.php";
  75. // display what the person searched for.
  76.  if( isset ($resultmsg)){
  77.   echo $resultmsg;
  78.   exit();
  79.  }else{
  80.  
  81. foreach($newarr as $value){
  82.  
  83. // EDIT HERE and specify your table and field names for the SQL query
  84. $query_value = "SELECT * FROM users WHERE username = '$value'";
  85.  $num_value=mysql_query ($query_value);
  86.  $row_linkcat= mysql_fetch_array ($num_value);
  87.  $row_num_links= mysql_num_rows ($num_value);
  88.  
  89. //now let's make the keywods bold. To do that we will use preg_replace function. 
  90. //EDIT parts of the lines below that have fields names like $row_linkcat[ 'field1' ]
  91. //This script assumes you are searching only 3 fields. If you are searching more fileds make sure that add appropriate line. 
  92.   $titlehigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'username' ] );
  93. foreach($trimmed_array as $trimm){
  94.  
  95. //end highlight
  96.     $connections="select * from users where username like'%$trimm%'";
  97.     $result=mysql_db_query($database_logon,$connections);
  98.     $total=mysql_num_rows($result);
  99.     $totalpages=ceil($total/$each);
  100.     $goto = ($page-1)*$each;
  101.  
  102. $connections="select * from users where username like'%$trimm%'  order by username  limit $goto,$each";
  103. $result=mysql_db_query($database_logon,$connections);
  104. $num=mysql_num_rows($result);
  105.  
  106.             while($rs=mysql_fetch_array($result)) {
  107. $username=$rs[username];
  108. $password=$rs[password];
  109. $userid=$rs[userid];
  110. $userlevel=$rs[userlevel];
  111. $email=$rs[email];
  112. $timestamp=$rs[timestamp];
  113. $photo=$rs[photo];
  114. $sex=$rs[sex];
  115. $province=$rs[province];
  116. $aboutme=$rs[aboutme];
  117. $vote=$rs[vote];
  118. $lookfor=$rs[lookfor];
  119. $figure=$rs[figure];
  120.  
  121.        echo "<table width=\"580\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" align=\"center\" id='search_page'><tr>";
  122.          if ($photo=="") { 
  123.       echo "<td ><IMG SRC='site_img/nophoto.gif' width='95' height='95' border='1'/></td>";
  124.      }else {
  125.       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\">
  126. <IMG SRC=\"prof_photo/$photo\" width=\"95\" height=\"95\" BORDER=\"1\" ></A></td>";}
  127.       echo"<td><div id='searchDivUserName'>username : <a href=\"seeprof.php?id=$username\"> $username </a><br>";
  128.                 if ($sex=="M") {
  129.                     echo "เพศ : ชาย<br>";
  130.                  } else if ($sex=="W") {
  131.                     echo "เพศ : หญิง<br>";
  132.                  }  else if($sex=="G") {
  133.                     echo "เพศ : เกย์<br>";
  134.                  }  else if ($sex=="T") {
  135.                     echo "เพศ : ทอม<br>";
  136.                  }  else if($sex=="D") {
  137.                     echo "เพศ : ดี้<br>";
  138.                  }    else if($sex=="B") {
  139.                     echo "เพศ : Bisexual<br>";
  140.                  }
  141. echo"จังหวัด : $p[$province]
  142.       </div></td>";
  143.       echo" <td ><div id='searchDivLink'>
  144.       <a href ='seeprof.php?id=$username'>ดูโปรไฟล์</a>
  145.       <a href ='sendmail.php?id=$username'>ส่งอีเมลย์</a>
  146.  
  147.  
  148.       </div></td>
  149.   </tr>
  150. </table><tr>";
  151.  
  152.  
  153. }
  154.  
  155.  }
  156.  
  157. }
  158. }
  159.  
  160. ?><br />
  161.           <br />
  162.           </div>
  163.           <div id="imgpage">            
  164. <?
  165.  
  166.     if ($totalpages>1) { 
  167.         echo "<B>หน้า $page</B><BR>";
  168.          for ($i=1;$i<=$totalpages;$i++) {
  169.         echo "| <A HREF='search_name.php?q=$q&submit=Search&page=$i'>$i</A> ";
  170.         }
  171.     }
  172. ?>
  173. </div>
  174.           <br />
  175.           <br />
  176.         </div>
  177.       </div>
  178.       </div>
  179.     </div>
  180.     <br />
  181.     <div id="footer">
  182. </div>
  183.   </div>
  184. </div>
  185. </body>
  186. </html>
Sep 11 '07 #11
pbmods
5,821 Expert 4TB
Heya, Alex.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Sep 11 '07 #12
paitoon
62
Oh Im sorry sir. I will remember now.
Sep 11 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
5
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...
8
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. ...
5
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...
0
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...
19
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...
8
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...
3
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...
1
adelemb
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.