Jump to content

[SOLVED] Query help needed


Salis

Recommended Posts

(SELECT * FROM blogs WHERE username='$username' ORDER BY pid DESC LIMIT $limit)

 

OK, This works. My buddy and I own a web site. We both have bolgs and as a most servers have it we are limited to how many databases we can have. I created a database that contains the content of our site and I have also created a table labeled blogs. OK this table holds the blogs for both of us and is working very nice. Well I when I structured the database I added a row labeled Deleted with a default value 'false'. The idea is simple, if that value is true then the corresponding entry will not be displayed.

 

if( $us_row['Deleted'] == 'false'] ) {

echo $us_row['Entry'];

}

 

This also works. But my problem is that this effects the number of entries displayed. I would like a constant number of blog entries to be displayed, say 10, but if one is 'Deleted' then only 9 are shown. My question is, is there something I can add to the query exclude the entries with a true valued? Does this make since?

Link to comment
https://forums.phpfreaks.com/topic/44363-solved-query-help-needed/
Share on other sites

Well after a long search online I found what I was looking for:

 

(SELECT * FROM blogs WHERE (username='$username') AND deleted NOT IN ('true') ORDER BY pid DESC LIMIT $limit);

 

Which "AND deleted NOT IN ('true')" is a little confusing... ("and where true is not in deleted"...)

  • 2 months later...

Usually IN() is most useful with more than one value, such as a list of values.  It's more standard, easier to read, and possibly faster, to use something like:

 

SELECT * FROM blogs WHERE username='$username' AND deleted != 'true' ORDER BY pid DESC LIMIT $limit
// or
SELECT * FROM blogs WHERE username='$username' AND deleted ='false' ORDER BY pid DESC LIMIT $limit

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.