Jump to content

how to search data


baby83

Recommended Posts

i have this html code... to search a data.

<form name="form1" method="post" action="search.php">
          <p align="center">
            <input type="text" name="search">
            <input type="submit" name="Submit" value="Search">
            <input type="reset" name="Reset" value="Reset">
          </p>
          <p align="center">  </p>
      </form> 

and this is my sql code...

$search = $_POST['search'];
$query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic"); 
while ($row = mysql_fetch_array($query)) 
{ 
$a_id = $row['a_id'];

$ic=$row['ic']; 
$a = $row['a'];
$b=$row['b'];
echo "<center>";

echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
echo "
<tr>";
echo "<td colspan='2'>";
print ("Info: ");
echo "$ic";
echo "</td>";
echo "<td>";
echo "$a";
echo "</td>";
echo "<td>";
echo "$b";
echo "</td>";
echo "</tr>";

 

i get this result:

 

Info:   mark     susan

 

Info:   mark     anita

 

'mark' is in field 'a' and 'susan and anita' is in field b.

 

the problem is, when i search the ic, it shows both infos. yes, in my table, it contains:

 

example:

 

a_id     a           b        ic

1        mark   susan    1011

2        mark   anita     1011

 

i want the result shows like this:

 

info:   mark     susan

                    anita

 

can anybody help me?

Link to comment
https://forums.phpfreaks.com/topic/116357-how-to-search-data/
Share on other sites

try changing this line...

$query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic"); 

 

to this:

$query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic") or die("Problem in query!"); 

 

and let us know if you get any errors.

Link to comment
https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598287
Share on other sites

Try...

<?php
$search = $_POST['search'];
$query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic"); 

if(mysql_num_rows($query) < 1) {
  die("There was no results found!");
}

$row = mysql_fetch_array($query); 
$a_id = $row['a_id'];

$ic=$row['ic']; 
$a = $row['a'];
$b=$row['b'];
echo "<center>";

echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
echo "
<tr>";
echo "<td colspan='2'>";
print ("Info: ");
echo "$ic";
echo "</td>";
echo "<td>";
echo "$a";
echo "</td>";
echo "<td>";
echo "$b";
echo "</td>";
echo "</tr>";
?>

Link to comment
https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598292
Share on other sites

ok... then ive got this result...

 

Info: mark      susan

 

but how about the info about....  mark and anita?

 

because in my table... i have:

 

id          a            b                  ic

1          mark        susan          1011

2          mark        anita            1011

 

so if i search '1011', it will shows:

 

Info:  mark        susan

                      anita

 

can u help me?

Link to comment
https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598296
Share on other sites

ok.... actually i want to show the result like this:

 

Info:  mark      susan

                    anita

 

it means: mark has 2 daug name susan and anita.

 

i separate it because both susan and anita have their own details.

 

example: in my table:

 

id        a          b          ic            age

1      mark      susan    1011        20

2      mark      anita      1011        15

 

yes i agree your given code is correct. but it doesnt show all the daug that mark has... hmmm...

Link to comment
https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598308
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.