0 Replies Latest reply on Mar 5, 2011 7:53 AM by freedeluder

    Mysql database search not sowing the result

    freedeluder

      <?php
      header("Content-type: text/html; charset=utf-8");
      // include MySQL-processing classes
      
      require_once 'mysql.php';
      
      try{
      
      // connect to MySQL
      
      $db=new MySQL(array
      ('host'=>'xxx','user'=>'xxx','password'=>'xxx',
      'database'=>'my_db'));
      
      $searchterm=$db->escapeString($_GET['searchterm']);
      
      $result=$db->query("SELECT words FROM my_table WHERE words LIKE '$searchterm'");
      
      if(!$result->countRows()){
      
      echo '<div class="maincontainer"><h2>No results were found. Go
      back and try a new search.</h2></div>'."";
      
      }
      
      else{
      
      // display search results
      
      echo '<div class="maincontainer"><h2>Your search criteria
      returned '.$result->countRows().' results.</h2>'."";
      
      while($row=$result->fetchRow()){
      
      echo '<div class="rowcontainer"><p><strong>Test</strong>'.$row['words'].'<p></div>'."";
      
      }
      
      }
      
      echo '</div>';
      
      }
      
      catch(Exception $e){
      
      echo $e->getMessage();
      
      exit();
      
      }
      
      ?>
      

       

      Hi, can someone explain to me why on the page are not showing the results supposed to show? The code is not mine, but I am trying to figure it out...

       

      So the idea is simple. I am searching for a word in a database and the results is counting as 1, as supposed to, but on echo, is not showing the result.

       

      Thanks.