hey am 17 and just really got a good grasp of php and html and all this i tried to put a site together... Basically I have a web site that pulls
products from a data base
links
description
img url
price
....
I have a search script for the query...
and if i dnt put the full name word for word into search bar it wont bring resaults out...
Heres My website Tckdeals
Heres A copy of my snytax
<?php
require_once('config.php');
require_once('common.php');
// get settings from database
$query = "SELECT * FROM config LIMIT 1;";
database_inquiry($query, $rows);
extract($rows[0]);
$search = custom_get('search');
$fromprice = custom_get('fromprice',0);
$toprice = custom_get('toprice',0);
$page = custom_get('page',1);
if (!is_numeric($page)) $page = 1;
// bound products if price ranges exist
$sqlparm = '';
$and = '';
if ($search != '')
{
if (stristr($search,'+') == false && stristr($search,'-') == false && stristr($search,'"') == false && stristr($search,'(') == false && stristr($search,'*') == false)
{
$sqlparm .= "match(name, description) AGAINST('$search')";
}
else
{
$sqlparm .= "match(name, description) AGAINST('$search' IN BOOLEAN MODE)";
}
$and = ' AND';
}
if ($fromprice > 0)
{
$sqlparm .= "$and sale_price >= '$fromprice'";
$and = ' AND';
}
if ($toprice > 0)
{
$sqlparm .= "$and sale_price <= '$toprice'";
$and = ' AND';
}
if ($sqlparm == '')
{
$sqlparm .= "match(name, description) AGAINST('$search')";
}
if (stristr($search,'+') == true || stristr($search,'-') == true || stristr($search,'"') == true || stristr($search,'(') == true || stristr($search,'*') == true)
{
if ($product_order == 1)
{
$sqlparm .= ' ORDER BY sale_price ASC';
}
if ($product_order == 2)
{
$sqlparm .= ' ORDER BY sale_price DESC';
}
}
// get category lists
$category_list = array();
$query = "SELECT id, name FROM categories WHERE parent_id = '';";
database_inquiry($query, $rows);
$category_list = $rows;
// set database limits
$start = ($page-1)*$products_per_page;
$limits = " LIMIT $start,$products_per_page";
// create next/prev links
$query = "SELECT count(*) AS count from products WHERE $sqlparm;";
database_inquiry($query, $rows);
$product_count = $rows[0]['count'];
$total_pages = $product_count / $products_per_page;
if ($total_pages != intval($total_pages)) $total_pages++;
$total_pages = (int) $total_pages;
if ($total_pages < 1) $total_pages = 1;
// create page numbers
$from_page = $page-4;
$to_page = $page+4;
if ($from_page < 1){$from_page = 1;}
if ($to_page > $total_pages){$to_page = $total_pages;}
$search2 = stripslashes($search);
$search2 = urlencode(($search2));
$search2 = str_replace('"','"',$search2);
$page_array = '';
for ($i=$from_page;$i<=$to_page;$i++)
{
$page_array .= "<a href=\"search.php?search=$search2&page=$i&fromprice=$fromprice&toprice=$toprice\">$i </a>";
}
$next_prev = '';
$prev_page = $page-1;
$next_page = $page+1;
if ($page > 1) $next_prev .= "<a href=\"search.php?search=$search2&page=$prev_page&fromprice=$fromprice&toprice=$toprice\"><<Prev</a> | "; else $next_prev .= "<<Prev | ";
$next_prev .= $page_array;
if ($page < $total_pages) $next_prev .= "<a href=\"search.php?search=$search2&page=$next_page&fromprice=$fromprice&toprice=$toprice\">| Next>></a>"; else $next_prev .= "| Next>>";
if ($total_pages == 1)
{
$next_prev = '';
}
// Get merchant list
$query = "SELECT * from datafeeds;";
database_inquiry($query, $rows);
$affiliates = $rows;
// Get product list
$query = "SELECT * from products WHERE $sqlparm $limits;";
database_inquiry($query, $rows);
$product_list = format_product_list($rows, $products_per_line);
// Generate inner template
$tpl = new Template();
$tpl->set('top_ad',$top_ad);
$tpl->set('bottom_ad',$bottom_ad);
$tpl->set('product_list',$product_list);
$tpl->set('next_prev',$next_prev);
$tpl->set('search',$search);
$main_content = $tpl->fetch('templates/default/search.tpl');
// Generate outer template
$tpl2 = new Template();
$tpl2->set('main_content',$main_content);
$tpl2->set('site_name',$site_name);
$tpl2->set('site_slogan',$site_slogan);
$tpl2->set('template',$template);
$tpl2->set('title',$site_name.' :: '.$search);
$tpl2->set('description',$site_name.' '.$search);
$tpl2->set('keywords',$site_name.' '.$search);
generate_custom_menu($cust_menu, $cust_menu_items);
$tpl2->set('cust_menu',$cust_menu);
$tpl2->set('cust_menu_items',$cust_menu_items);
$tpl2->set('menu',generate_menu());
$tpl2->set('news_menu',generate_news_menu(10));
$x = $tpl2->fetch("templates/$template/master.tpl");
// Generate html page
echo $x;
?>
<?php @include('database.php'); ?>
HERE ARE THE FUNTIONS
function custom_get($get_var, $default="")
{
$value = $default;
if (!get_magic_quotes_gpc()) {
if (isset($_GET["$get_var"])) {$value = addslashes($_GET["$get_var"]);}
} else {
if (isset($_GET["$get_var"])) {$value = $_GET["$get_var"];}
}
return(htmlspecialchars($value));
}
Demo Of What My issue Is...
https://plus.google....89/videos?hl=en
please help me
5 replies to this topic
#1
Posted 30 January 2012 - 10:57 AM
|
|
|
#2
Posted 03 February 2012 - 11:20 PM
Please use code tags, nobody will really help you without them.
#3
Posted 14 February 2012 - 03:21 PM
yeah i couldnt really read this.. so i didnt,but if you had a table like this:
[table="width: 500"]
[tr]
[td]Johnathan[/td]
[td]lindemann[/td]
[/tr]
[tr]
[td]billyjohn[/td]
[td]truman[/td]
[/tr]
[tr]
[td]Billy[/td]
[td]Ray[/td]
[/tr]
[/table]
and you wanted to make a search engine, you have to make the query something like this:
in human terms, it would say SELECT the firstname FROM the table name WHERE the firstname is similiar to john connecting from the front or the back. 'john%' would display johnathan and john. '%john' would display billyjohn and '%john%' would display both of them. so the % signs are just an indication. make sense?
This is the bare essentials of making a search engine
[table="width: 500"]
[tr]
[td]Johnathan[/td]
[td]lindemann[/td]
[/tr]
[tr]
[td]billyjohn[/td]
[td]truman[/td]
[/tr]
[tr]
[td]Billy[/td]
[td]Ray[/td]
[/tr]
[/table]
and you wanted to make a search engine, you have to make the query something like this:
$query = "SELECT 'firstname' FROM 'table_name' WHERE 'firstname' LIKE '%john%' ";
in human terms, it would say SELECT the firstname FROM the table name WHERE the firstname is similiar to john connecting from the front or the back. 'john%' would display johnathan and john. '%john' would display billyjohn and '%john%' would display both of them. so the % signs are just an indication. make sense?
This is the bare essentials of making a search engine
Edited by Jmancuso, 14 February 2012 - 05:46 PM.
#4
Posted 15 February 2012 - 01:30 PM
Jmancuso said:
in human terms, it would say SELECT the firstname FROM the table name WHERE the firstname is similiar to john connecting from the front or the back. 'john%' would display johnathan and john. '%john' would display billyjohn and '%john%' would display both of them. so the % signs are just an indication. make sense?
This is the bare essentials of making a search engine
This is the bare essentials of making a search engine
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#5
Posted 15 February 2012 - 01:45 PM
yeah i recommend you read up on table collation and make sure you choose the right one for your table.
latin1_swedish_ci is non case sensitive. im pretty sure this is the default
latin1_swedish_ci is non case sensitive. im pretty sure this is the default
#6
Posted 15 February 2012 - 01:50 PM
Yes it is, the ci in the end is for "case insensitive". On the other hand, that is for mysql. There are many other database engines out there, with other setups.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









