Showing number of records returned after search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jasone
    New Member
    • Mar 2007
    • 66

    Showing number of records returned after search

    Hi all,

    ive got a search working, as shown below... on the page i want to show how many records are returned, im sure this is pretty simple but cant really work it out.

    any help or advice would be much appreiciated :-)

    Code:
      <?php
        include "flowermatchdbcnx.php";
    	 $r = $_POST['occcas']; //users choice... e.g. birthday, anniversary etc.
    	 $s = $_POST['style']; //display type... modern or classic.
    	 $p = $_POST['price']; //price, need to be within the price range. 
    	 $t = $_POST['type']; //flower suitability.... mother father collegue etc.
    	 $pak = $_POST['pacakge']; //flowers packaging
    	 
    	//The query to the database
    	
    	
    	
    	$query = ("SELECT * FROM products WHERE style IN ('$s') AND occcas IN ('$r') AND type IN ('$t') AND pacakge IN ('$pak') AND price IN ('$p')");
    
    switch ($p){
    	case "1":$query=($query." WHERE Price BETWEEN 0 AND 20");break;
    	case "2":$query=($query." WHERE Price BETWEEN 21 AND 30");break;
    	case "3":$query=($query." WHERE Price BETWEEN 31 AND 40");break;
    	case "4":$query=($query." WHERE Price BETWEEN 41 AND 50");break;
    	
    			}
    	
    	
    	$result = mysql_query($query);
    	//while loop to go through database table search all matching records.
    	
    	while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    	
    	echo "name :{$row['Product_ID']} <br>";
    	echo "type :{$row['style']} <br>";
    		
    
    }
    	
    ?>
    </body>
    hope the code snippet above helps.

    secondly, i may as ask while im here, ive had a problem searching for number ranges, i tried using the 'switch' statement above but it didnt work, so ive resorted adding a column stating 10 - 20 etc and it looks up that field in the table, what is the best way to search for a price range without changing the code above too much?
    :-)
    many thanks in advance
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    To the first question

    i'm thinking you'd need the mysql_num_rows( )

    Don't have time for the second question at the moment!

    Hope that gets you someehwere.

    Comment

    Working...