kujur Posted April 29, 2007 Share Posted April 29, 2007 Hi, Am new to PHP infact am just a learner i tried searching products and services and result that am getting is fine but it displayes the subcategory 2 times where i want it to display subcatgoey once and display the numrows in a category here is the code $productservice = $_POST["productservice"]; // Setting the variable for query $country = $_POST["country"]; // Setting the variable for query // how many rows we have in database $query = "SELECT COUNT(productservice) AS numrows FROM matter where productservice like '%$productservice%' and country='$country'"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; $query = "SELECT * FROM matter where productservice like '%$productservice%' and country='$country' ORDER BY matter.scid DESC LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); if ($numrows !='0') echo( " <p class=author>Your Search for <b>$productservice</b> <b>$country</b> has generarted <b>$numrows</b> matches. pg. $pageNum</p> <hr> " ); if( $result ) { while( $lookfor = mysql_fetch_object( $result ) ) { // print out the info ( `name` , `age`, `email`,`about` ) $category = $lookfor -> category; $subcategory = $lookfor -> subcategory; $scid = $lookfor -> scid; $nameid = $lookfor -> nameid; $query2 = "SELECT COUNT(nameid) AS numrows2 FROM matter where scid='$scid'"; $result2 = mysql_query($query2) or die('Error, query failed'); $row2 = mysql_fetch_array($result2, MYSQL_ASSOC); $numrows2 = $row2['numrows2']; if ($numrows2 =='0') { echo( " <p><b>$category</b> - <a href=companies.php?scid=$scid>$subcategory</a></p> <hr> " ); } else { echo( " <p><b>$category</b> - <a href=companies.php?scid=$scid>$subcategory</a></p> <p>$numrows2</p> <hr> " ); } } } else { die( "Trouble getting contacts from database: " . mysql_error() ); } I wish to have the result eg if we search for flower the result should be flower-flower garden - 1, flower-flower shop -2 right now i get flower-flower shop 2 and agian it is repeated flower-flower shop 2 the live example is here http://directory.kujur.net/find.php Search for flower and select country Mauritius Link to comment https://forums.phpfreaks.com/topic/49220-search-result-of-category-to-display-number-of-the-entries/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.