Some help with this please!
11-13-2008, 04:44 AM
|
Some help with this please!
|
Posts: 961
Name: Darren
Location: England
|
Hi, I am trying to modify some old code that was written a while back for an old site.
The page displays a set of results that are deturmined from a 2 dropdwon menus on a previous page "make" & "model" - This results page then returns all the products available for that selection.
What I am trying to do is create a results page that has the make and model manually entered into the code so that page will always have the results for that particular make & model...
Sort of need to remove the search faciltity if you like... (hope this all makes sense!)
Cheers,
PHP Code:
<?php
//info bars colour
$color_info = "#D6D685";
// Almost Silver //FFFFCC
$color1 = "#E9E9E9";
// Light Blue
$color2 = "#EAD5FF";
// Light Blue
/*
Wykes Online Products Database and Querying System
filename: results.php
version: 1.1
last revision: 15/2/03
description: search results page to display the results from basic search
*/
//include header code
include_once ("head.php");
//include function library code
include_once ("func_lib.php");
// use the user_connection include file's connectDB function
include_once ("usr_conn.php");
if (!connectDB())
{
echo "<p>Unable To Connect To Database</p>";
return;
}
//test that make and model are passed in, if they are assign them
if (($_GET['make'] == "MAKE") or ($_GET['model'] == "MODEL"))
{
$errMessage = "<br><br><b><font class=small>Your search hasn't returned any results, please re-enter your search again.</font></b><br><br><a href=van_accessories.php>Search again</a><br><br>";
}
else
{
// get search values for make and model, removing " and ' chars
$strMake = mysql_escape_string($_GET['FORD --------------- van products']);
$strModel = mysql_escape_string($_GET['Courier 1992 on']);
}
// set the Prod_Type that is to be shown regardless of car make and model
$strDefaultProd = "XD";
//write query string that will pased in paging links
$strQuery = "make=" . $strMake . "&model=" . $strModel . "&";
//echo $strQuery;
//grab the page number that we're on
$page = mysql_escape_string($_GET['page']);
//$strMake = "FIAT";
//$strModel = "Uno";
//create sql query
$sqlSelect = "SELECT Prod_ID, Prod_Type, Prod_Model, Prod_Make, Prod_REF, Product_Desc, Price_ExVat, image_name FROM products";
$criteria = " WHERE (Car_Make = '" . $strMake . "' AND Car_Model = '" . $strModel . "') OR (Car_Make = 'all') AND Default_Code <> 'LE'";
//$criteria = " WHERE Car_Make = '".$strMake."' AND Car_Model = '".$strModel."'";
// assign the basic sqlquery
$sqlquery = $sqlSelect . $criteria;
//echo $sqlquery; #debug
//get the result set
$result = mysql_query($sqlquery);
$count = mysql_num_rows($result);
$full_count = $count;
//set max number of records per page
$records_per_page = 999;
//Next figure out how many pages you'll have.
$total_pages = ceil($count / $records_per_page);
/*
This just sets up a page variable which will be past in a "next" and "prev"
link. The first link to this page may not actually have $page so this just
sets it up.
*/
if ($page == "")
{
$page = 1;
}
//echo "<br>page number".$page; #debug
# this will set up the "First | Prev | " part of our navigation.
if ($page == 1)
{
# if we are on the first page then "First" and "Prev"
# should not be links.
$naviagation = "<font color=\"#666666\">First</font> | <font color=\"#666666\">Prev</font> | ";
}
else
{
# we are not on page one so "First" and "Prev" can
# be links
$prev_page = $page - 1;
$navigation = "<a href=\"results.php?" . $strQuery . "page=1\">First</a> | <a href=\"results.php?" . $strQuery . "page=" . $prev_page . "\">Prev</a> | ";
}
# this part will set up the rest of our navigation "Next | Last"
if ($page == $total_pages)
{
# we are on the last page so "Next" and "Last"
# should not be links
// $navigation .= "<font color=\"#666666\">Next</font> | <font color=\"#666666\">Last</font>";
}
else
{
# we are not on the last page so "Next" and "Last"
# can be links
$next_page = $page + 1;
$navigation .= "<a href=\"results.php?" . $strQuery . "page=" . $next_page . "\">Next</a> | <a href=\"results.php?" . $strQuery . "page=" . $total_pages . "\">Last</a>";
}
/*
The final thing to do is your actual query, but first we have to figure out
what the offset will be.
*/
$offset = ($page - 1) * $records_per_page;
//echo "<br>offset".$offset; #debug
//create sql query
$sqlSelect = "SELECT Car_Make, Car_Model, Prod_ID, Prod_Type, Prod_Model, Prod_Make, Priority, Prod_Code, Prod_REF, Product_Desc, Price_ExVat, Link, image_name FROM products";
$criteria = " WHERE (Car_Make = '" . $strMake . "' AND Car_Model = '" . $strModel . "') OR (Car_Make = 'all') AND Default_Code <> 'LE'";
$limit = " ORDER BY Priority ASC, Prod_Code ASC, Prod_ID ASC LIMIT $offset, $records_per_page";
// assign the basic sqlquery
$sqlquery = $sqlSelect . $criteria . $limit;
//echo $sqlquery;
//get the result set
$result = mysql_query($sqlquery);
// if no matches found from query
if (!$result || (mysql_num_rows($result) == 0))
{
//echo ("<b><font class=small>No matches were found.</font></b>");
}
// display the results
else
{
// use rowcount to display total results found
$count = mysql_num_rows($result);
//echo $count;
//echo("<p>Total Matches Found = " . $rowCount . "</p>"); //*debug
}
?>
__________________
I Just a test to see what happens... Please login or register to view this content. Registration is FREE
"Let us be thankful for the fools. But for them the rest of us could not succeed..."
|
|
|
|
11-13-2008, 04:57 AM
|
Re: Some help with this please!
|
Posts: 565
Name: surajit ray
Location: inside the heart of my friends
|
I am afraid i dn't understand you properly. but did you tried that:
PHP Code:
if (($_GET['make'] == "MAKE") or ($_GET['model'] == "MODEL")) { $strMake = "Your default make"; $strModel = "Your default model"; }
__________________
I am not smart, that's why i don't act smart
Please login or register to view this content. Registration is FREE
|
|
|
|
11-13-2008, 05:03 AM
|
Re: Some help with this please!
|
Posts: 961
Name: Darren
Location: England
|
Hmm, that just returns a blank page...
Have a look here
This is a search page that takes you to the results for the vehicle that is selected.
What I want is to create a results page per vehicle and force the results to appear on that page. i.e.
Ford_focus.php will show the results for a Ford Focus.
Hope that makes it a bit clearer!
__________________
I Just a test to see what happens... Please login or register to view this content. Registration is FREE
"Let us be thankful for the fools. But for them the rest of us could not succeed..."
|
|
|
|
11-13-2008, 05:10 AM
|
Re: Some help with this please!
|
Posts: 565
Name: surajit ray
Location: inside the heart of my friends
|
try with :
if( $strMake == "")
{
$strMake = "Your default make";
}
if($strModel== ""){
$strModel = "Your default model";
}
just over your query. This will show the default values. and print the query to see.
__________________
I am not smart, that's why i don't act smart
Please login or register to view this content. Registration is FREE
Last edited by jito; 11-13-2008 at 05:34 AM..
Reason: missed the variable :(
|
|
|
|
11-13-2008, 05:15 AM
|
Re: Some help with this please!
|
Posts: 219
Name: Rob
Location: UK
|
What you want is a combined search and results page.
Transfer the results code over to the search page and just surround the results page code with a simple conditional so it parses only when a search is submitted eg
PHP Code:
if ($_GET) { // results code }
|
|
|
|
11-13-2008, 12:00 PM
|
Re: Some help with this please!
|
Posts: 961
Name: Darren
Location: England
|
Ok, I've added the "search page" code into it... er... what now??!
PHP Code:
<?php
//info bars colour
$color_info = "#D6D685";
// Almost Silver //FFFFCC
$color1 = "#E9E9E9";
// Light Blue
$color2 = "#EAD5FF";
// Light Blue
/*
Wykes Online Products Database and Querying System
filename: results.php
version: 1.1
last revision: 15/2/03
description: search results page to display the results from basic search
*/
//include header code
include_once ("head.php");
//include function library code
include_once ("func_lib.php");
// use the user_connection include file's connectDB function
include_once ("usr_conn.php");
if (!connectDB())
{
echo "<p>Unable To Connect To Database</p>";
return;
}
$sqlSelect = "SELECT DISTINCT Car_Make FROM products WHERE Car_Make <> 'all' and Car_Make <> 'link' and Default_Code <> 'LE' and Car_Make <> 'n/a'";
$sqlquery = $sqlSelect;
$result = mysql_query($sqlquery);
if (!$result || (mysql_num_rows($result) == 0)){
}
else{
$count = mysql_num_rows($result);
}
$totalOutput = "";
while ($row = mysql_fetch_assoc($result))
{
$strMake = $row["Car_Make"];
$outMake = "regions[\"".$strMake."\"] = ";
$sqlSelectModel = "SELECT DISTINCT Car_Model FROM products WHERE Car_Make = '".$strMake."' and Default_Code <> 'LE'";
$sqlqueryModel = $sqlSelectModel;
$resultModel = mysql_query($sqlqueryModel);
if (!$resultModel || (mysql_num_rows($resultModel) == 0)){
}
else{
$countModel = mysql_num_rows($resultModel);
}
$i = $countModel;
$outModel = "[\"";
while ($rowModel = mysql_fetch_assoc($resultModel))
{
$strModel = $rowModel["Car_Model"];
$outModel = $outModel.$strModel;
if ($i > 1){
$outModel = $outModel."\", \"";
}
else{
$outModel = $outModel;
}
$i = $i-1;
}
$outModel = $outModel."\"];";
$carOutput = $outMake.$outModel;
$totalOutput = $totalOutput.$carOutput."\n";
}
if ($_GET) {
// results code
}
//test that make and model are passed in, if they are assign them
if (($_GET['make'] == "MAKE") or ($_GET['model'] == "MODEL"))
{
$errMessage = "<br><br><b><font class=small>Your search hasn't returned any results, please re-enter your search again.</font></b><br><br><a href=van_accessories.php>Search again</a><br><br>";
}
else
{
// get search values for make and model, removing " and ' chars
$strMake = mysql_escape_string($_GET['FORD --------------- van products']);
$strModel = mysql_escape_string($_GET['Courier 1992 on']);
}
// set the Prod_Type that is to be shown regardless of car make and model
$strDefaultProd = "XD";
//write query string that will pased in paging links
$strQuery = "make=" . $strMake . "&model=" . $strModel . "&";
//echo $strQuery;
//grab the page number that we're on
$page = mysql_escape_string($_GET['page']);
//$strMake = "FIAT";
//$strModel = "Uno";
//create sql query
$sqlSelect = "SELECT Prod_ID, Prod_Type, Prod_Model, Prod_Make, Prod_REF, Product_Desc, Price_ExVat, image_name FROM products";
$criteria = " WHERE (Car_Make = '" . $strMake . "' AND Car_Model = '" . $strModel . "') OR (Car_Make = 'all') AND Default_Code <> 'LE'";
//$criteria = " WHERE Car_Make = '".$strMake."' AND Car_Model = '".$strModel."'";
// assign the basic sqlquery
$sqlquery = $sqlSelect . $criteria;
//echo $sqlquery; #debug
//get the result set
$result = mysql_query($sqlquery);
$count = mysql_num_rows($result);
$full_count = $count;
//set max number of records per page
$records_per_page = 999;
//Next figure out how many pages you'll have.
$total_pages = ceil($count / $records_per_page);
/*
This just sets up a page variable which will be past in a "next" and "prev"
link. The first link to this page may not actually have $page so this just
sets it up.
*/
if ($page == "")
{
$page = 1;
}
//echo "<br>page number".$page; #debug
# this will set up the "First | Prev | " part of our navigation.
if ($page == 1)
{
# if we are on the first page then "First" and "Prev"
# should not be links.
$naviagation = "<font color=\"#666666\">First</font> | <font color=\"#666666\">Prev</font> | ";
}
else
{
# we are not on page one so "First" and "Prev" can
# be links
$prev_page = $page - 1;
$navigation = "<a href=\"results.php?" . $strQuery . "page=1\">First</a> | <a href=\"results.php?" . $strQuery . "page=" . $prev_page . "\">Prev</a> | ";
}
# this part will set up the rest of our navigation "Next | Last"
if ($page == $total_pages)
{
# we are on the last page so "Next" and "Last"
# should not be links
// $navigation .= "<font color=\"#666666\">Next</font> | <font color=\"#666666\">Last</font>";
}
else
{
# we are not on the last page so "Next" and "Last"
# can be links
$next_page = $page + 1;
$navigation .= "<a href=\"results.php?" . $strQuery . "page=" . $next_page . "\">Next</a> | <a href=\"results.php?" . $strQuery . "page=" . $total_pages . "\">Last</a>";
}
/*
The final thing to do is your actual query, but first we have to figure out
what the offset will be.
*/
$offset = ($page - 1) * $records_per_page;
//echo "<br>offset".$offset; #debug
//create sql query
$sqlSelect = "SELECT Car_Make, Car_Model, Prod_ID, Prod_Type, Prod_Model, Prod_Make, Priority, Prod_Code, Prod_REF, Product_Desc, Price_ExVat, Link, image_name FROM products";
$criteria = " WHERE (Car_Make = '" . $strMake . "' AND Car_Model = '" . $strModel . "') OR (Car_Make = 'all') AND Default_Code <> 'LE'";
$limit = " ORDER BY Priority ASC, Prod_Code ASC, Prod_ID ASC LIMIT $offset, $records_per_page";
// assign the basic sqlquery
$sqlquery = $sqlSelect . $criteria . $limit;
//echo $sqlquery;
//get the result set
$result = mysql_query($sqlquery);
// if no matches found from query
if (!$result || (mysql_num_rows($result) == 0))
{
//echo ("<b><font class=small>No matches were found.</font></b>");
}
// display the results
else
{
// use rowcount to display total results found
$count = mysql_num_rows($result);
//echo $count;
//echo("<p>Total Matches Found = " . $rowCount . "</p>"); //*debug
}
?>
__________________
I Just a test to see what happens... Please login or register to view this content. Registration is FREE
"Let us be thankful for the fools. But for them the rest of us could not succeed..."
|
|
|
|
11-13-2008, 12:45 PM
|
Re: Some help with this please!
|
Posts: 219
Name: Rob
Location: UK
|
At present your search page is submitting to the results page. This needs to be changed to <?php $_SERVER['PHP_SELF'] ?> ie the form submits to itself.
This code <form action="results.php"> needs to be changed to
PHP Code:
<form action="<?php $_SERVER['PHP_SELF'] ?>">
Is this what your after - might have misunderstood you 
|
|
|
|
|
« Reply to Some help with this please!
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|