Jump to content

Need help on search function


andylai

Recommended Posts

I try to create a search function for mysql database on the web page but it didn't works.  Can anyone help?

 

Thanks.

 

Andy

 

 

<?php

include ("db.php");

 

$path="file:\\\fileserver\WDrawing";

$path1="file:\\\fileserver\ADrawing";

 

?>

 

 

<html>

  <body>

  <h1 align="center"> Drawing File list </h1>

  <hr> 

  <?php echo $search; ?>

  <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="GET">

 

 

      Search:

      <input type="text" name="search">

      <input type="submit" value="GO">

      <hr>

    </form>

</div>

<BR>

<?php

if (isset($action)){

$result = mysql_query_ec("SELECT filename,code FROM filelist where filename like %$search%");

while ($filename = mysql_fetch_assoc($result))

      {     

      $filename = $row["filename"];

      $code = $row["code"];

     

      If ($code == "w") {

        $fn=$path."\\".substr($filename,0,1)."\\".$filename;

        echo "<a href='$fn'>$filename</a><br>";

        }

      else {

        $fn=$path1."\\".$filename;

        echo "<a href='$fn'>$filename</a><br>";

        }

      }

      header ("location:index1.php"); 

      exit;

}

?>

   

  </body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/
Share on other sites

When I type a word in search and submit it, nothing reply on the result. 

I have another page that will display all file and that works.

Thanks

Andy

 

 

I try to create a search function for mysql database on the web page but it didn't works.  Can anyone help?

 

Thanks.

 

Andy

 

 

<?php

include ("db.php");

 

$path="file:\\\fileserver\WDrawing";

$path1="file:\\\fileserver\ADrawing";

 

?>

 

 

<html>

  <body>

  <h1 align="center"> Drawing File list </h1>

  <hr> 

  <?php echo $search; ?>

  <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="GET">

 

 

      Search:

      <input type="text" name="search">

      <input type="submit" value="GO">

      <hr>

    </form>

</div>

<BR>

<?php

if (isset($action)){

$result = mysql_query_ec("SELECT filename,code FROM filelist where filename like %$search%");

while ($filename = mysql_fetch_assoc($result))

      {     

       $filename = $row["filename"];

       $code = $row["code"];

       

       If ($code == "w") {

         $fn=$path."\\".substr($filename,0,1)."\\".$filename;

         echo "<a href='$fn'>$filename</a><br>";

        }

      else {

         $fn=$path1."\\".$filename;

         echo "<a href='$fn'>$filename</a><br>";

        }

      }

      header ("location:index1.php"); 

      exit;

}

?>

   

  </body>

</html>

$result = mysql_query_ec("SELECT filename,code FROM filelist where filename like %$search%");

 

where are you defining $search? and what is mysql_query_ec ? A google search returned nothing on this statement.

 

Try doing this

 

$query="SELECT filename,code FROM filelist where filename like %$search%";
$result = mysql_query($query);

echo $query;

 

take a look at the echo'd query and see if it is populating the $search var.

 

 

 

 

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.