roldahayes Posted November 12, 2008 Share Posted November 12, 2008 Hi, I am trying to modify some code that was written for an old site we had. This is the search results page with displays the results from a previous page that has 2 dropdown menus - "make" & "model" What I am trying to do is create a results page by manully entering the make and model into this page to display the results... I'm entering it in all the obvious places but can get the right info to display.. Any suggestions? <?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['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 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 } ?> EDITED BY WILDTEEN88: Cleaned up code Quote Link to comment https://forums.phpfreaks.com/topic/132448-solved-help-with-sorting-this-code-out-please/ Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 lol that is a pain in the butt to look at. Please remove the extra spaces and paste a cleaned up version. That is just horrendus for me to even want to try and help honestly. Quote Link to comment https://forums.phpfreaks.com/topic/132448-solved-help-with-sorting-this-code-out-please/#findComment-688617 Share on other sites More sharing options...
roldahayes Posted November 13, 2008 Author Share Posted November 13, 2008 Looks like someone has very kindly done that for me! Can anyone help with the original problem now please? Quote Link to comment https://forums.phpfreaks.com/topic/132448-solved-help-with-sorting-this-code-out-please/#findComment-689153 Share on other sites More sharing options...
roldahayes Posted November 14, 2008 Author Share Posted November 14, 2008 aha sorted it! $criteria = " WHERE (Car_Make = '" . $strMake . "' AND Car_Model = '" . $strModel . "') OR (Car_Make = 'all') AND Default_Code <> 'LE'"; to $criteria = " WHERE (Car_Make = 'enter make here' AND Car_Model = 'enter model here') OR (Car_Make = 'all') AND Default_Code <> 'LE'"; Quote Link to comment https://forums.phpfreaks.com/topic/132448-solved-help-with-sorting-this-code-out-please/#findComment-690057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.