Jump to content

Search System


pudge1

Recommended Posts

  $user = SQL_User();
  $pass = SQL_Pass();
  $dbname = SQL_DB();

  $search_term = mysql_real_escape_string($search_term);

  $connection = mysql_connect('localhost',$user,$pass);

  mysql_select_db($dbname, $connection);

  $sql = "SELECT * FROM Notes WHERE Keywords LIKE '%$search_term%'";

   if($subject == 'NO')
    {
    }
   else
    {
     $sql .= " AND Subject='$subject'";
    }

   if($grade == 'NO')
    {
    }
   else
    {
     $sql .= " AND Grade='$grade'";
    }

   if($sort_by == 'NO')
    {
    }
   elseif($sort_by == 'RATING')
    {
     $sql .= " ORDER BY Rating DESC";
    }
   elseif($sort_by == 'VIEWS')
    {
     $sql .== " ORDER BY Views DESC";
    }
   else
    {
    }

  $query = mysql_query($sql, $connection);
  $query = mysql_fetch_array($query);

 

Will query output a multi-dimensional array? If not how does it separate each result?

Link to comment
Share on other sites

Oops copied the wrong problem sorry.

 

function Search($keyword,$subject,$grade,$search_by)
{
  $user = SQL_User();
  $pass = SQL_Pass();
  $dbname = SQL_DB();

  $connection = mysql_connect('localhost',$user,$pass);

  mysql_select_db($dbname , $connection);

  $search_term = mysql_real_escape_string($search_term);

  $sql = "SELECT * FROM Notes WHERE Keywords LIKE '%$search_term%'";

   if($subject == 'NO')
    {
    }
   else
    {
     $sql .= " AND Subject='$subject'";
    }

   if($grade == 'NO')
    {
    }
   else
    {
     $sql .= " AND Grade='$grade'";
    }

   if($sort_by == 'NO')
    {
    }
   elseif($sort_by == 'RATING')
    {
     $sql .= " ORDER BY Rating DESC";
    }
   elseif($sort_by == 'VIEWS')
    {
     $sql .= " ORDER BY Views DESC";
    }
   else
    {
    }

  $query = mysql_query($sql , $connection);

    while($arr = mysql_fetch_array($query))
     {
      $title = file_get_contents('notes/' . $arr['Note_ID'] . '.note');
      $title = explode('||TITL_E=',$title);
      $title = $title[1];
      $title2 = explode('=||',$title);

      $user = SQL_User();
      $pass = SQL_Pass();
      $dbname = SQL_DB();

      $search_term = mysql_real_escape_string($search_term);

      $connection = mysql_connect('localhost',$user,$pass);

      mysql_select_db($dbname, $connection);

      $sql = "SELECT * FROM Notes WHERE Note_ID='$note_id'";
      $query = mysql_query($sql , $connection);
      $query = mysql_fetch_array($query);

      $title = $query["Title"];

      $contents = $title2[1];
      $contents2 = wordwrap($contents, 80, ",", true);
      $contents2 = explode(',',$contents2);
      $contents2 = $contents2[0];

       if($contents2 == $contents)
        {
        }
       else
        {
         $contents = $contents . '...';
        }

      $results .= "<a id='search_title' href='view_note.php?id=" . $arr['Note_ID'] . "'>" . $title . "</a><br />";
      $results .= "<span id='search_contents'>" . $contents . "</span><br />";
      $results .= "<span id='search_author'>" . $arr['Author'] . "</span><br /><br /><br />|*|?|>|";
     }

     return $results;
  }

 

For some reason I get these errors

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/functions.php on line 713

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/functions.php on line 713

 

I've looked over this many times. I even took the SQL Statement ($sql) and put it through the SQL Command on PHPMyAdmin and replaced the variable with what I am using as a keyword and it works just fine. But I can't figure out quite what is wrong.

 

Line 713 Begins with While($arr...

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.