Location: PHPKode > projects > BlueBoy What's New > bb_news_search.php3
<?
//////////////////////////////////////////////////////////////////////////////////////////
//                                                                                      //
//  BlueBoy Whats New APP v. 1.0.3
//  Search Engine                                                     //
//  by Mike Norton                                                                      //
//  hide@address.com   http://www.blueboymultimedia.com                                  //
//                                                                                      //
//  You may use this to your hearts content.  It is Open Source :-)                     //
//                                                                                      //
//                                                                                      //
//  Special thanks to Angus Mackay [hide@address.com] for the code
//////////////////////////////////////////////////////////////////////////////////////////


///  MAIN APP  /////////////

// Database entry points.  Gets all info from config.inc
//
require ("bb_news_config.inc");

if($querystr == "")
{
  print "Search News
  <p>
    <form action=\"$SCRIPT_NAME\" method=get>
    <input type=text name=querystr size=20>
    <input type=submit name=submit value=Search>
    </form>
  </p>
  ";
}
else
{

  if($page_number == "") { $page_number = 0; }
  $page_offset = $page_number * $max_hits;
  $prev_page_number = $page_number - 1;
  $next_page_number = $page_number + 1;


  mysql_connect($bb_news_hostname,$bb_news_mysqluser,$bb_news_mysqlpassword)
		or die("Unable to connect to SQL server");  // We do this to handle the errors

  // news is the name of the table
  //
  // We select only 5 of the latest records here, ordered by id number.  You can change that
  // to any number you would like or you can take it out all together
  //
  $query = "select id, subject, news,  date_format(date, '%Y/%m/%d %h:%i %p') as date, 
      author, link from news
      where subject like '%$querystr%' or news like '%$querystr%'
      order by id desc limit $page_offset,$max_hits";   

  $news =  mysql_db_query($bb_news_db, $query) or die("Select Failed!");

  if(mysql_num_rows($news) == 0)
  {
    print "<h2>No Matches Found</h2>
      <p>
      There were no matches for your query
      </p>
    ";
  }

  print "
    <font face='Arial'><b>Search Results</b></font>
  ";

  // We do this untill there is nothing left to do in the select statment.
  //
  while ($row = mysql_fetch_array($news)) 
  {


  // Formating is completly up to you.  This is a sample.
  //
  // Color settings are in config.inc
  //
  ?>

  <font face="Arial, Helvetica, sans-serif" size="2">
  <font color="<? echo $bb_news_date_fn; ?> "><? echo $row['date']; ?></font> by <font color="<? echo $bb_news_author_fn; ?>"><? echo $row['author']; ?></font><br>
    <b><font color="<? echo $bb_news_subject_fn; ?>"><? echo $row['subject']; ?></font></b><br>
      <font color="<? echo $bb_news_text_fn; ?>">
      <? echo $row['news']; ?><br></font>
      <a href="<? echo $row['link']; ?>"><? echo $row['link']; ?></a></font> 
      </font></div><font face="Arial, Helvetica, sans-serif" size="2">
  <br>


  <?
  // Now we are done.  Simple call this file from within your php3 app useing
  // require ("bb_news.php3"); in your code.  Dont forget to include the open and close php

  }

  $human_pnum = $page_number + 1;
  print "
    <table width=100%><tr><td align=left>
    Page $human_pnum
    </td>
    <td align=right>
  ";
  $qs = ereg_replace('\&page_number=[^&]*', '', $QUERY_STRING);
  if($prev_page_number > -1)
  {
    print "<a href=\"$SCRIPT_NAME?$qs&page_number=$prev_page_number\">prev</a> \n";
  }
  else
  {
    print "prev\n";
  }
  if(mysql_num_rows($news) == $max_hits)
  {
    print "<a href=\"$SCRIPT_NAME?$qs&page_number=$next_page_number\">next</a> \n";
  }
  else
  {
    print "next\n";
  }
  print "
    </td>
    </tr>
    </table>
  ";

}
 
?>
Return current item: BlueBoy What's New