<?php # search.inc.php
/*
* This is the search content module.
* This page is included by index.php.
* This page expects to receive $_GET['terms'].
*/
// Redirect if this page was accessed directly:
if (!defined('BASE_URL')) {
// Need the BASE_URL, defined in the config file:
require_once ('../includes/config.inc.php');
// Redirect to the index page:
$url = BASE_URL . 'index.php?p=search';
// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
$db_password="<snipped>";
$db_name="search";
$db_tb_name="search";
$db_tb_atr_name="keywords";
//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");
$query=mysql_real_escape_string($_GET['terms']);
$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE
$db_tb_atr_name like '%".$query."%'");
echo "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo "<li>";
echo substr($data_fetch[$db_tb_atr_name], 0,160);
echo "</li><hr/>";
}
echo "</ol>";
mysql_close();
}
?>
This post has been edited by Atli: 09 October 2012 - 01:26 PM
Reason for edit:: Please post code in [code] tags, rather than attach it.

New Topic/Question
Reply



MultiQuote




|