Somi Rana Somi Rana - 1 year ago 64
PHP Question

how to get search value from data base using php if 2 or 3 words same to stored data base value

my code is fine and its working well but i have to write same term as its stored in data base
like if i want to search a value named"awais123" which is stored in data base i have to write same term as "awais123"
if i will write awa or aws it will return nothing

//my datauser.php

<form action="data2.php" method="post" class="navbar-form navbar-right">
<div class="input-group">
<input type="Search" name="user_name" value="" placeholder="Search..." class="form-control" />
<div class="input-group-btn">
<button class="btn btn-info">
<span class="glyphicon glyphicon-search"></span>
< /div>

//now my "data2.php"


$query = "SELECT * FROM user WHERE user_name='".$username."'";
$result = $conn ->query($query) or die("Query error");
<table width="983" border="1" cellpadding="5" class="insertTable">

<td width="109"><strong>user name</strong></td>

<td width="38"><strong>user phone no</strong></td>
<td width="99"><strong>dept id</strong></td>
<td width="40"><strong></strong></td>
foreach($result as $row)


<td><?php echo $row['user_name']; ?></td>

<td><?php echo $row['user_phone_no']; ?></td>
<td><?php echo $row['dept_id']; ?></td>
<td><a href="delete.php?id=<?php echo $row['user_name']; ?>">Delete</a> </td>

please help me i just want that if just 3 words are found in my term its display result

Answer Source

Change you $query to:-

$query = "SELECT * FROM user WHERE user_name LIKE '%".$username."'%";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download