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
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"...)

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.