SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: quick sql help

  1. #1
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    quick sql help

    Hello,

    I have a peice of code that works fine but 1 part of it. I need it to select all support notes that are not flagged which `flagged` = '0'. However, it is also pulling up flagged support notes as well, and flagged is `flagged` = 1. So I am not sure what I did wrong if someone can help me out?

    PHP Code:
    SELECT FROM `notestrack` AS `notes1WHERE `itemidNOT IN (SELECT `itemidFROM `notesWHERE `usergroup` != AND `flagged` = '0') AND id = (SELECT MAX(idFROM `notesWHERE notes1.itemid = `itemid`) ORDER BY `idDESC 

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    What type is the flagged field in your database? varchar, int, bool, etc...

    If any field is integer or a bool, it should be unquoted.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thanks for the help, it is:

    PHP Code:
     `flaggedsmallint(1NOT NULL default '0'

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Okay, well try removing the quotes from all non-string values, and if you still need forther help with this we'll see what the good people in the MySQL forum can do to help with this.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    quoted or unquoted won't make a difference, mysql will convert quoted string values.

    show us some sample rows from your database, which ones are being returned and which of those that shouldn't be returned.

  6. #6
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thanks for all your help, I still cant find out whats wrong, taking the "" away didnt do anything, below is an example row.

    PHP Code:
    INSERT INTO `notessss` (`id`, `email`, `date`, `user`, `usergroup`, `url`, `itemid`, `question`, `flagged`) VALUES (1'jon@email.com''2009-03-16''testaccount''2''http://www.firewaterrepair.com/''400576''testy'0), 

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Please share the column structure of notessss

    Code sql:
    DESCRIBE notessss;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't post a single row as an insert statement. you need to show us several rows for us to determine what is wrong with your query. show us the rows and which ones are/are not being returned and why the should/shouldn't be returned.

    a create table(s) statement with actual inserts (like you provided above) would help us to help you better.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •