Excluding some Results

Discussion in 'PHP' started by soundzet.comcoder, Jul 29, 2009.

  1. #1
    Hello,

    Can you please help me with this one i have this querry that i use to get a ranking from a mysql database
    i would like to make something to exclude some results how can i do it what i have to write?

    Thanks alot this is my code,


    $conn = mysql_connect($host,$user,$pass) or die("Unable to connect to MySQL server");
    
     mysql_select_db($db,$conn) or die("Unable to select to MySQL database");
     
    		$query = "select search_log.keyword  as search_log_keyword, search_log.count as search_log_count from search_log order by search_log.count desc limit 500"; 
    						
    		$results = mysql_query($query); 		
    
    
    		
    
    			$count = 0;
    
    
    
    		if(!$results) 
    		{
    			echo 'query failed'; 
    		}
    		else 
    		{
                    while($row=mysql_fetch_assoc($results))
    			{
    				
    				
    				
    				$songName = $row['search_log_keyword'];  
    
            $count++;
    
    				print(""); 
    				/*print("<td ><a href='songs.php?id=".$row['song_id']."'><img src='$artistPhoto' width='25' height='20'/></a></td>");*/
    				print("<table width='100%'  border='0'>
      <tr>
        <td width='9%'><p style='margin-bottom: 4px; color: #472424;' >$count</p></td>
        <td width='2%'>&nbsp;</td>
        <td width='72%'><a href='index.php?search=$songName&source=All'>$songName</a>
    			</p></td>
      </tr>
    </table>");
    				print("<center><img src='templates/soundzet/images/dotted2.png' /></center>");				
    				print("");  
    			}
    		}		
    	
    
    
    
    ?>
    PHP:
     
    soundzet.comcoder, Jul 29, 2009 IP
  2. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #2
    There's two mainstream ways to accomplish this. If there is a kind of pattern to what you want to ignore, such as the ID being over a certain limit or the timestamp is in a certain range, than all you need to do is alter your SQL.

    I'm assuming it isn't this easy (and there is no pattern to what you want to exclude), so what else you will need to do is make an "ignore" column in your table. For the results you want to ignore in this query, mark it as 1. For the results you do NOT want to ignore in this query, mark it as 0. When you've done all this, just edit your query so that it says:
    "select search_log.keyword as search_log_keyword, search_log.count as search_log_count from search_log WHERE ignore='0' order by search_log.count desc limit 500"

    Let me know if this works. If the table is dynamic enough (that is, rows are added constantly), you may need to determine if the result should be ignored or not when it is added (and require more updating)
     
    tguillea, Jul 29, 2009 IP