Jump to content

Search Problem


yash87

Recommended Posts

Hi,

 

Can I know how to resolve this problem?

 

Notice: Undefined variable: x in C:\wamp\www\i-document\search.php on line 39

 

Notice: Undefined variable: construct in C:\wamp\www\i-document\search.php on line 41

1 results found!

 

Thankz.

 

 

 


<html>
<body>
   <form id="form1" method="GET" action="search.php">
        <table width="446" height="135" border="1" align="center">
          <tr>
            <td height="31" colspan="2" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">Search :</span></td>
          </tr>
          <tr>
            <td width="374" height="96" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">
              <label>
              <div align="left">Keyword :
                <input name="search" type="text" id="search" size="40" />
              </div>
              </label>
            </span>
            <td width="56" align="center" valign="middle" bgcolor="#990000">
              <div align="left">
                <input type = "submit" name="submit" value="search" />
            </div></td>
          </tr>
        </table>
      </form>
</body>
</html>



[b][u]search.php[/u][/b]

<html>
<title>Search</title>

</head>

<body><br /><br />
<div class="MySearch"></div><br />
<?php

//Get data


$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button)
   echo "You didn't submit a keyword.";
else
{
   if (strlen($search)<=1)
      echo "Search term too short";
   else
   {
      echo "You searched for <b>$search</b><hr size='1'>";

      //connect to database
      mysql_connect("localhost","root","");
      mysql_select_db("idoc");

             
            //explode search term
            $search_exploded = explode(" ",$search);

            foreach($search_exploded as $search_each);
            {

                //Construct Query

                $x++;
                if ($x==1)
                   $construct .= "file_name LIKE '%$search_each%'";
                else
                   $construct .= " OR file_name LIKE '%$search_each%'";

            }

     

      //echo out construct

     $construct = "SELECT * FROM document WHERE $construct";
     $run = mysql_query($construct);

     $foundnum = mysql_num_rows($run);

     if ($foundnum==0)
        echo "No results found";
     else
     {
        echo "$foundnum results found!<p>";

        while ($runrows = mysql_fetch_assoc($run))
        {
         //Get data
         $ref = $runrows['file_ref'];
     $filename = $runrows['file_name'];
	 $owner = $runrows['owner'];
         $url = $runrows['url'];
         echo "
        <table>
	<tr>
		 <td> $ref </td>
		 <td> $filename </td>
		 <td> $owner </td>
		 <td><a href='$url'>$url</a></td>

	</tr> 
	</table>
         ";
        }

     }


   }
}

?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.