|
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";
|
* = are the keyword that typed by user |
here is the entire search.php file if needed
[PHP]<?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> ";
}
$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> ";
}else
$pages .= "<a href="search.php?origin=$origin&gender=$_GET[gender]&letter=$_GET[letter]&page=$i">$i</a> ";
}
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 & Daftar Nama Bayi, Anak, Indonesia, Laki, Perempuan";
}
if($page == 1){
$title = "Hasil Cari Nama $gender - $origin. Arti & Daftar Nama Bayi, Anak, Indonesia, Laki, Perempuan";
}
include "template.php";
?>
[/PHP]
I can’t understand the words that are coming out of your mouth
You want %$l% in your SQL statements …
A search against my PHPBB3 database returns 4 results for this:
SELECT * FROM `phpbb_users` WHERE username like "re%"
It returns 33 including the first 4 with this:
SELECT * FROM `phpbb_users` WHERE username like "%re%"
Hope that helps …