Jump to content

Can Anyone Help With This Please??


roldahayes

Recommended Posts

Hi,

 

I am trying to display all results for a certain search criteria.

 

I need to display all available products no matter what category they are in - depending  on the make and model searched for...

 

Using my code, the results return everything in the database....

 

Can anyone please advise the right way to do this.

 


$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."' AND Default_Code = 'RS' OR Default_Code = 'LE')";

Link to comment
https://forums.phpfreaks.com/topic/259542-can-anyone-help-with-this-please/
Share on other sites

this is the original version that only displays the categories, before I started playing with it....

 

[php$criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'RS') OR (Car_Make = 'all' AND Car_Model = 'all' AND Default_Code = 'SA')";][/code]


/ get search values for make and model, removing " and ' chars
$strMake = mysql_escape_string($_GET ['make']);


$strModel = mysql_escape_string($_GET ['model']);

	}



// 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, Image_Van FROM products";

                                                                                        //change this back to 'FILL THIS IS IN' to switch accessories off!

$criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'RS') OR (Car_Make = 'all' AND Default_Code = 'SA')";


//$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=\"all.php?".$strQuery."page=1\">First</a> | <a href=\"all.php?".$strQuery."page=".$prev_page."\">Prev</a> | ";















}










Sorted it...

 

Not sure if this is the best way, but it works fine!

 

$criteria = " WHERE (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'LE') OR (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'CV') OR (Car_Make = '".$strMake."' AND Car_Model = '".$strModel."' AND Default_Code = 'RS') OR (Car_Make = 'all' AND Default_Code = 'RA')";

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.