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
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> | ";















}










Link to comment
Share on other sites

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')";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.