brosskgm Posted April 12, 2012 Share Posted April 12, 2012 I have some PHP/Java code that was written for me that searches and displays an item(s) costs etc. Similar to a parts store but with a eCart twist. This was so long ago that I'm no longer able to contact the coder. He no longer in school and they can't tell you were he went to. I guess he got a good grade for the project and got hired. I only have about 20-25 items in the database. Can someone tell here where in the attached code I can tell it to display all the contents of the database with out using the search but leaving all the other functions usable? If you need any other files not in the attachment, let me know. There are several more, but these were most of the php files in the main directory. Thanks in advance. Bob Ross 18055_.zip Quote Link to comment Share on other sites More sharing options...
trq Posted April 12, 2012 Share Posted April 12, 2012 Sounds to me like you need to hire another programmer. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2012 Share Posted April 12, 2012 It looks like your search class is what does the searching. You would need to post the search.php code. Quote Link to comment Share on other sites More sharing options...
brosskgm Posted April 12, 2012 Author Share Posted April 12, 2012 Sorry. There wasn't much in there and I wasn't sure if it would have been needed. Search.php <?php require_once "dbConnect.php"; Class Search { private $ResultArray, $numRows; public function __construct() { if ($_GET['s']) { $safeQuery = mysql_real_escape_string($_GET['s']); $theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'"; $res = mysql_query($theQuery); $this->numRows = mysql_num_rows($res); $i = 0; while ($result = mysql_fetch_array($res)) { $this->ResultArray[$i] = $result; $i++; } } else { $this->numRows = -1; } } public function getResult() { return $this->ResultArray; } public function getNumRows() { return $this->numRows; } public function __destruct() { mysql_close(); } } ?> It looks like your search class is what does the searching. You would need to post the search.php code. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2012 Share Posted April 12, 2012 You would just modify the query logic so that if no search term is provided, you retrieve all rows from the table - <?php public function __construct() { if(isset($_GET['s']) && $_GET['s'] != '') { $safeQuery = mysql_real_escape_string($_GET['s']); $theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'"; } else { $theQuery = "SELECT * from parts"; } $res = mysql_query($theQuery); $this->numRows = mysql_num_rows($res); $i = 0; while ($result = mysql_fetch_array($res)) { $this->ResultArray[$i] = $result; $i++; } } The starting query does not have any ORDER BY term in it, so you just get the rows in the order that they are stored in the table. You should probably add an ORDER BY term to both queries so that your product information is retrieved in some specific order, such as alphabetical by product name. Quote Link to comment Share on other sites More sharing options...
brosskgm Posted April 12, 2012 Author Share Posted April 12, 2012 What file would I put this in? Thanks You would just modify the query logic so that if no search term is provided, you retrieve all rows from the table - <?php public function __construct() { if(isset($_GET['s']) && $_GET['s'] != '') { $safeQuery = mysql_real_escape_string($_GET['s']); $theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'"; } else { $theQuery = "SELECT * from parts"; } $res = mysql_query($theQuery); $this->numRows = mysql_num_rows($res); $i = 0; while ($result = mysql_fetch_array($res)) { $this->ResultArray[$i] = $result; $i++; } } The starting query does not have any ORDER BY term in it, so you just get the rows in the order that they are stored in the table. You should probably add an ORDER BY term to both queries so that your product information is retrieved in some specific order, such as alphabetical by product name. Quote Link to comment Share on other sites More sharing options...
brosskgm Posted April 12, 2012 Author Share Posted April 12, 2012 You would just modify the query logic so that if no search term is provided, you retrieve all rows from the table - <?php public function __construct() { if(isset($_GET['s']) && $_GET['s'] != '') { $safeQuery = mysql_real_escape_string($_GET['s']); $theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'"; } else { $theQuery = "SELECT * from parts"; } $res = mysql_query($theQuery); $this->numRows = mysql_num_rows($res); $i = 0; while ($result = mysql_fetch_array($res)) { $this->ResultArray[$i] = $result; $i++; } } The starting query does not have any ORDER BY term in it, so you just get the rows in the order that they are stored in the table. You should probably add an ORDER BY term to both queries so that your product information is retrieved in some specific order, such as alphabetical by product name. Quote Link to comment 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.