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
https://forums.phpfreaks.com/topic/210896-search-system/
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
https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100041
Share on other sites

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.