counting rows of results of database

Discussion in 'PHP' started by gilgalbiblewheel, Jun 19, 2008.

  1. #1
    What is the script to count the results of your search from a database?

    More specifically (or maybe another question) is how to display the result if it finds more than 3 words searched:.

    $searchTheseArr = explode(" ", $searchTheseArr);
    //echo count($searchTheseArr);
    $sql="SELECT * FROM db_table WHERE 1=1 AND";
    for ($i=0; $i < count($searchTheseArr); $i++) {
    	if(strlen($searchTheseArr[$i]) > 3){
    		$sql.=" text_data LIKE '" .$searchTheseArr[$i]. "'";
    		if($i!=count($searchTheseArr)-1){
    			$sql.=" OR";
    		}
    	}
    }
    PHP:
    If I'm not clear show me where I should be more specific. Thanks!
     
    gilgalbiblewheel, Jun 19, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    
    $searchTheseArr = explode(" ", $searchTheseArr);//echo count sear chTheseArr);
    $sql="SELECT * FROM db_table WHERE 1=1 AND";for ($i=0; $i < count($searchTheseArr); $i++) {    
    if(strlen($searchTheseArr[$i]) > 3){        
    $sql.=" text_data LIKE '" .$searchTheseArr[$i]. "'";        
    if($i!=count($searchTheseArr)-1){            
    $sql.=" OR";        
    }    
    }
    }
    
    
    $result = mysql_query($sql);
    if(mysql_num_rows($result)> 3){
    
       $row = mysql_fetch_array($result);
       
       for($x = 0;$x < count($row) -1;$x++){
    
          echo $row[$x].'<br>';
    
       }
    
    }
    
    
    
    PHP:
     
    php-lover, Jun 19, 2008 IP
  3. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #3
    Number of rows in resulted reource

    $res = mysql_query("..............");
    $num_rows = mysql_num_rows($res);


    I could not follow the second question.

    regards
     
    Vooler, Jun 20, 2008 IP
  4. nastynappy

    nastynappy Banned

    Messages:
    499
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if (strlen($_POST['search']) > 3)
    {
    // run sql queirs
    }
     
    nastynappy, Jun 20, 2008 IP