/    Sign up×
Community /Pin to ProfileBookmark

How to search a space delimited string, with non-delimited keywords string?

I have a problem, i wish somebody would help me out.

I have a database that store a phone numbers, and i have a web application that have a search feature. Numbers that stored in the database is with a space delimited (example : 0888 991 999), it is no problem to find this number if the search keyword is 999, but consider that i want to find a number with my sister birth year at the end, it is not found if the keyword is 1999.

How the script should be, so i the program can find the number? How can i find 0888 991 999 with a keyword is 1999? I just have an ordinary search script that would find an exact match.

[code=php]<?php
$cari_input = $_POST[‘field’];
$cari_input = mysql_escape_string($cari_input);
$cari=”SELECT * from tb_perdana where hp_nomor like ‘%$cari_input%’ order by hp_price desc”;
$cari_query=mysql_query($cari);
$num=mysql_num_rows($cari_query);
$jml=0;
while($show_nmr=mysql_fetch_row($cari_query)){ //showing search results
$a[$jml][0] = $show_nmr[0]; // id
$a[$jml][1] = $show_nmr[1]; // date
$a[$jml][2] = $show_nmr[2]; // networks
$a[$jml][3] = $show_nmr[3]; // operators
$a[$jml][4] = $show_nmr[4]; // phone numbers
$a[$jml][5] = $show_nmr[5]; // price
$a[$jml][6] = $show_nmr[6]; // category
$a[$jml][7] = $show_nmr[7]; // pair
$a[$jml][8] = $show_nmr[8]; // ban status
$a[$jml][9] = $show_nmr[9]; // order status
$jml++;
}
?>[/code]
[code=html]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<table width=”100%” border=”0″ align=”center” cellspacing=”0″ cellpadding=”0″>
<tr>
<td colspan=”4″>Searching a phone numbers with a key <strong><?=$cari_input?></strong> :<hr /></td>
</tr>
<tr>
<td align=”center”>Phone Number</td><td align=”center”>Network</td><td align=”center”>Operator</td><td align=”right” style=”padding-right:50px;”>Price</td>
</tr>
<tr>
<td colspan=”4″><hr /></td>
</tr>[/code]
[code=php]
<?php
for($s=0;$s<$num;$s+=1){
echo “<tr>”;
$p=$s;

$l = $p+1;
if ($p==”” || !eregi(“^[0-9]”,$p) || $p>$num){
$p = 0;
}
if($num<=$l){
$n=$num;
} else {
$n=$l;
}
for ($i=$p;$i<$n;$i++){
$harga = “”.$a[$i][5].””;
$harga = number_format($harga);
$harga = str_replace(“,”,”.”,$harga);
if(!$_SESSION[‘user’]) {
$hal = “?page=login.aspx&amp;pesan=”.$a[$i][4].”&amp;title=Buat Keranjang Belanja”;
} else {
$hal = “?page=keranjang.aspx&amp;pesan=”.$a[$i][4].”&amp;user=”.$_SESSION[‘user’].”&amp;title=Keranjang Belanja&amp;item=add&amp;online=ok”;
}
if($a[$i][9]==”0″) {
if($a[$i][8]==”0″){
$no = “”.$a[$i][4].”<font color=”#FF0000″ size=”-2″>*</font>”;
} else {
$no = “”.$a[$i][4].””;
}
$class = “nomorhp_ok”;
$title = “Click here to order this number”;
$link = “<a href=”$hal” title=”$title”>$no</a>”;
} else if($a[$i][9]==”1″){
if($a[$i][8]==”0″){
$link = “”.$a[$i][4].”<font color=”#FF0000″ size=”-2″>*</font>”;
} else {
$link = “”.$a[$i][4].””;
}
$class = “nomorhp_off”;
$title = “Sorry, the has been ordered, please select other number or you can contact us”;
} else {
$class = “”;
$link = ‘&nbsp;’;
}
echo “<td align=”center” class=”$class” title=”$title” style=”border-bottom:#CCCCCC solid 1px;”>$link</td><td style=”border-bottom:#CCCCCC solid 1px;” align=”center”>”.$a[$i][2].”</td><td style=”border-bottom:#CCCCCC solid 1px;” align=”center”>”.$a[$i][3].”</td><td style=”border-bottom:#CCCCCC solid 1px; padding-right:15px;” align=”right”>Rp $harga,-</td>”;
}
echo “</tr>”;
}
?>[/code]
[code=html]
</table>
</body>
</html>[/code]

Please help me..

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 06.2008 — Perhaps you could remove the spaces via the MySQL replace() function?
[code=php]
$cari="SELECT * from tb_perdana where REPLACE(hp_nomor, ' ', '') like '%$cari_input%' order by hp_price desc";
[/code]
Copy linkTweet thisAlerts:
@marhen1985authorMay 07.2008 — Thank you...thank you very much.... It is works...
×

Success!

Help @marhen1985 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...