This file only search 'Begin with keyword', how to make it s

  • basketmen
  • Student
  • Student
  • basketmen
  • Posts: 68

Post 3+ Months Ago

[SIZE="4"][COLOR="blue"]This search.php file only search 'Begin with keyword' only, how to make it search 'Contain keyword'[/COLOR][/SIZE]



Quote:
for example there already a name in database, lets say James


1. right now if user search for 'Begin with keyword' like Ja, or Jam, it will showing it (James, and other name begin with that keyword)

2. but not if search for 'End with keyword' or 'Contain keyword', like mes, or ames, or ame (it will not showing James, and other name with that keyword in the middle or in the end)




i need to make it like no.2 above, can search for 'Contain keyword', not search for 'Begin with keyword' only. Please help guys what is the right code, i think here is the code part that responsible for it

$sq = "select * from names where $gn $ori and (name like '$l%' OR meaning like '$l%') order by name";

$sql = "Select * from names where $gn $ori and (name like '$l%' OR meaning like '$l%') order by name limit $limitvalue,$limit";


Quote:
* = are the keyword that typed by user
names = the database table contain name list
meaning = the database table contain name meaning list









here is the entire search.php file if needed

PHP Code: [ Select ]
<?php
include "conn.php";
 
$origin = $_GET[origin];
$gender = $_GET[gender];
$l = $_GET[letter];
 
 
$page=$_GET[page];
$limit=50;
 
 if(empty($_GET[page])){
       $page = 1;
     }
 
$limitvalue = $page * $limit - ($limit);
 
 
if($origin != "any") $ori = " and origin = '$origin'";
if($gender == "either") $gn = "(gender = 'male' or gender = 'female')";
if($gender != "either") $gn = "gender = '$gender'";
 
 
$sq = "select * from names where $gn $ori and (name like '$l%' OR meaning like '$l%') order by name";
$rst = mysql_query($sq) or die(mysql_error());
$totalrows = mysql_numrows($rst);
 
$sql = "Select * from names where $gn $ori and (name like '$l%' OR meaning like '$l%') order by name limit $limitvalue,$limit";
$rec = mysql_query($sql) or die(mysql_error());
 
 
 
 
 
$topcontent = "<table width='100%' cellpadding='3'>
      <tr>
      <th bgcolor='#FFEAF5' aling='left'>Nama</th>
      <th bgcolor='#FFEAF5' aling='left'>Jenis Kelamin</th>
      <th bgcolor='#FFEAF5' aling='left'>Asal</th>
      <th bgcolor='#FFEAF5' aling='left'>Arti</th>
      <th bgcolor='#FFEAF5' aling='left'>Detail</th></tr>";
 
$lowcontent = "<table width='100%' cellpadding='3'>";
 
 
$bg="#FFEAF5";
 
$ctr=0;
while($datas=mysql_fetch_array($rec)){
   if($bg=="#FFEAF5"){
      $bg="#ffffff";
    }else{
      $bg="#FFEAF5";
      }
$means=substr($datas[meaning],0,9999);
$link = str_replace(" ","_",$datas[name]);
if($datas[gender]=="female"){
      $gender = "Perempuan";
      }else{
      $gender = "Laki-Laki";
         }
   $topcontent .= "<tr><td bgcolor='$bg'><b><a href='$datas[id]/$link.html'>$datas[name]</a></b></td>
         <td bgcolor='$bg'>$gender</td>
         <td bgcolor='$bg'>Nama $datas[origin]</td>
         <td bgcolor='$bg'>$means</td>
         <td bgcolor='$bg'><a href='$datas[id]/$link.html' rel='nofollow'>Detail...</a></td></tr>";
$ctr++;
 
   }
 
 
 
/*
Page pagination
*/
$l = str_replace("%","",$letter);
 
$pages .= "<p align='left'>Page(s) ";
if($page > 1){
$pageprev = $page-1;
$pages .= "<a href=\"search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$pageprev\">PREV</a>&nbsp;";
}
 
$numofpages = ceil($totalrows / $limit);
 
$starting = $page - 5;
$ending = $page + 5;
 
if($starting < 0) $starting = 1;
if($ending > $numofpages) $ending = $numofpages;
 
for($i = $starting; $i <= $ending; $i++){
if($page == $i){
$pages .= "<b>". $i."</b>&nbsp;";
}else
$pages .= "<a href=\"search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$i\">$i</a>&nbsp;";
}
 
 
 
if($page < $numofpages){
$pagenext = ($page + 1);
$pages .="<a href=\"search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$pagenext\">NEXT</a>";
}
 
 
/*********************************************************************************/
 
 
 
 
 
 
 
$topcontent  .= "</table>";
$lowcontent  .= "</table>";
 
$heading = "Hasil Cari Nama $gender - $origin";
if($page > 1){
$title = "Hasil Cari Nama $gender - $origin $page. Arti &amp; Daftar Nama Bayi, Anak, Indonesia, Laki, Perempuan";
}
if($page == 1){
$title = "Hasil Cari Nama $gender - $origin. Arti &amp; Daftar Nama Bayi, Anak, Indonesia, Laki, Perempuan";
}
 
include "template.php";
 
?>
 
 
 
 
 
 
  1. <?php
  2. include "conn.php";
  3.  
  4. $origin = $_GET[origin];
  5. $gender = $_GET[gender];
  6. $l = $_GET[letter];
  7.  
  8.  
  9. $page=$_GET[page];
  10. $limit=50;
  11.  
  12.  if(empty($_GET[page])){
  13.        $page = 1;
  14.      }
  15.  
  16. $limitvalue = $page * $limit - ($limit);
  17.  
  18.  
  19. if($origin != "any") $ori = " and origin = '$origin'";
  20. if($gender == "either") $gn = "(gender = 'male' or gender = 'female')";
  21. if($gender != "either") $gn = "gender = '$gender'";
  22.  
  23.  
  24. $sq = "select * from names where $gn $ori and (name like '$l%' OR meaning like '$l%') order by name";
  25. $rst = mysql_query($sq) or die(mysql_error());
  26. $totalrows = mysql_numrows($rst);
  27.  
  28. $sql = "Select * from names where $gn $ori and (name like '$l%' OR meaning like '$l%') order by name limit $limitvalue,$limit";
  29. $rec = mysql_query($sql) or die(mysql_error());
  30.  
  31.  
  32.  
  33.  
  34.  
  35. $topcontent = "<table width='100%' cellpadding='3'>
  36.       <tr>
  37.       <th bgcolor='#FFEAF5' aling='left'>Nama</th>
  38.       <th bgcolor='#FFEAF5' aling='left'>Jenis Kelamin</th>
  39.       <th bgcolor='#FFEAF5' aling='left'>Asal</th>
  40.       <th bgcolor='#FFEAF5' aling='left'>Arti</th>
  41.       <th bgcolor='#FFEAF5' aling='left'>Detail</th></tr>";
  42.  
  43. $lowcontent = "<table width='100%' cellpadding='3'>";
  44.  
  45.  
  46. $bg="#FFEAF5";
  47.  
  48. $ctr=0;
  49. while($datas=mysql_fetch_array($rec)){
  50.    if($bg=="#FFEAF5"){
  51.       $bg="#ffffff";
  52.     }else{
  53.       $bg="#FFEAF5";
  54.       }
  55. $means=substr($datas[meaning],0,9999);
  56. $link = str_replace(" ","_",$datas[name]);
  57. if($datas[gender]=="female"){
  58.       $gender = "Perempuan";
  59.       }else{
  60.       $gender = "Laki-Laki";
  61.          }
  62.    $topcontent .= "<tr><td bgcolor='$bg'><b><a href='$datas[id]/$link.html'>$datas[name]</a></b></td>
  63.          <td bgcolor='$bg'>$gender</td>
  64.          <td bgcolor='$bg'>Nama $datas[origin]</td>
  65.          <td bgcolor='$bg'>$means</td>
  66.          <td bgcolor='$bg'><a href='$datas[id]/$link.html' rel='nofollow'>Detail...</a></td></tr>";
  67. $ctr++;
  68.  
  69.    }
  70.  
  71.  
  72.  
  73. /*
  74. Page pagination
  75. */
  76. $l = str_replace("%","",$letter);
  77.  
  78. $pages .= "<p align='left'>Page(s) ";
  79. if($page > 1){
  80. $pageprev = $page-1;
  81. $pages .= "<a href=\"search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$pageprev\">PREV</a>&nbsp;";
  82. }
  83.  
  84. $numofpages = ceil($totalrows / $limit);
  85.  
  86. $starting = $page - 5;
  87. $ending = $page + 5;
  88.  
  89. if($starting < 0) $starting = 1;
  90. if($ending > $numofpages) $ending = $numofpages;
  91.  
  92. for($i = $starting; $i <= $ending; $i++){
  93. if($page == $i){
  94. $pages .= "<b>". $i."</b>&nbsp;";
  95. }else
  96. $pages .= "<a href=\"search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$i\">$i</a>&nbsp;";
  97. }
  98.  
  99.  
  100.  
  101. if($page < $numofpages){
  102. $pagenext = ($page + 1);
  103. $pages .="<a href=\"search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$pagenext\">NEXT</a>";
  104. }
  105.  
  106.  
  107. /*********************************************************************************/
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. $topcontent  .= "</table>";
  116. $lowcontent  .= "</table>";
  117.  
  118. $heading = "Hasil Cari Nama $gender - $origin";
  119. if($page > 1){
  120. $title = "Hasil Cari Nama $gender - $origin $page. Arti &amp; Daftar Nama Bayi, Anak, Indonesia, Laki, Perempuan";
  121. }
  122. if($page == 1){
  123. $title = "Hasil Cari Nama $gender - $origin. Arti &amp; Daftar Nama Bayi, Anak, Indonesia, Laki, Perempuan";
  124. }
  125.  
  126. include "template.php";
  127.  
  128. ?>
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Simple, just wrap the variable with percent symbols...
Code: [ Select ]
$sql = "Select * from names where $gn $ori and (name like '%$l%' OR meaning like '%$l%') order by name limit $limitvalue,$limit";
Or is this not what you are talking about?

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 189 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.