We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,996 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to Exclude Some Result From a Particular Row of Table from Showing

I am using mysql_fetch_array to fetch result from a table of my database and I want to exclude results from particular users from being fetch together with others.
Example:

$result = mysql_query("SELECT * FROM users") 
                or die(mysql_error());  
                
        
        
        echo "<table border='1' cellpadding='10'>";
        echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Sex</th> <th>Username</th></tr>";

        while($row = mysql_fetch_array( $result )) {
                
                // echo out the contents of each row into a table
                echo "<tr>";
                echo '<td>' . $row['id'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['sex'] . '</td>';
                echo '<td>' . $row['username'] . '</td>';
                echo "</tr>"; 
        } 

        echo "</table>";

Example Results
ID First Name Last Name Sex Username
1 Adams John Male adamsjo
2 Jen Jensen Female jensenjen
3 Mark Mike Male miker
4 Mathew Denson Male denis
etc

How can i exclude results from the first two rows of ID 1 and 2 from showing together with the rest of the result?

2
Contributors
3
Replies
30 Minutes
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
deyesborn
Newbie Poster
7 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
'SELECT * FROM users where id > 2'
diafol
Keep Smiling
Moderator
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Wow! I just used this query and it works:

$result = mysql_query("SELECT * FROM users WHERE id NOT IN ('1', '2')") 
                or die(mysql_error());
deyesborn
Newbie Poster
7 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

@Ardav, thanks so much, that also work well

deyesborn
Newbie Poster
7 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by diafol

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0677 seconds using 2.75MB