0

I have a problem in searching text in data, like search only street = Denover...
Here is my code. Pls help me. if i click button nothing happend...

Index.php

<?php  include_once '../templete/header.php'; ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="search.php" method="get" >
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><input type="text" name="query" id="text"  />&nbsp;</td>
    <td><input type="submit" name="submit" id="search" value="Search" /></td>
</form>
</body>
</html>

Search.php

<?php
 include_once '../templete/header.php';
 include_once '../inc/connection.inc.php';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table>    
<tr>
  <td>Name</td>
  <td>Address</td>
  </tr>   
<?php
    $query = $_GET['query'];

    //$stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%') OR (Address LIKE '%".$query."%')");
    $stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%' OR Address LIKE '%".$query."%')");
    $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    //$stmt->execute();
    if(isset($stmt))
        {
            while($row = $stmt->fetch()); ?>
              <tr>
              <td><?php echo $row['Name'];?></td>
              <td><?php echo $row['Address'];?></td>
              </tr>
        <?php
        }
?>
</table>    
</body>
</html>

Thanking you

maideen

2
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by Maideen
0

hai Maideen,

i think the following statement(at line no 26 in Search.php) might be the problem

you need to change from this

while($row = $stmt->fetch());   

to like this

while($row = $stmt->fetch()){
// your code goes here ....

}

i think you got the point and reason too

let me know the status

Edited by radhakrishna.p: clarity on the solution

0

Thank you mr.Radha

Solved. Really I appreciate you to help me.

Once again Thank you very much

Maideen

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.