SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I can't get this sql query to work? I want to select the rows witch have both the aid of 2 and vis of Y.

    select comment, name, email from comments where aid=2 and vis=Y;

    Thanks,
    Justin Sampson

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The query looks pretty straightforward. Would need to see the table structure though to make any corrections.
    Wayne Luke
    ------------


  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    justin only integeres can survive in the query without single quotes try

    select comment, name, email from comments where (aid=2) AND (vis='Y');
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Guru marcel's Avatar
    Join Date
    Nov 2000
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you need to put the Y in single quotes and remove the semi-colon at the end.

    eg:
    SELECT comment, name, email FROM comments WHERE aid=2 AND vis='Y'

    If you using PHP, there's no need to add the semi colon at the end, the parser puts it there for you. Yeah, php is cool like that.

    I might be able to help you some more if you provide details and code. As Luke suggested, a idea of the comments table would help too.

    The sample code I posted below should tell you exactly what error you have.

    Again, I'll assume that your using PHP.

    $docommand = mysql_query ("select comment, name, email from comments where aid=2 and vis=Y").$error_num = mysql_errno();

    if ($error_num > 0)
    {
    errormessage(); // display error
    }
    }


    /*
    Cheap Error message function
    */

    function errormessage() {

    echo mysql_error()."<BR>";
    exit();

    }


    Basically, instead of just saying: or die("Couldn't execute query."), you are telling the php parser to explain itself in english (sorta).

    This is accomplished by generating a error number and having mysql_error() interpret it.


    Just my 2 cents.

    Have fun.

  5. #5
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guys and Gals. I just hade to write it like:select

    comment, name, email from comments where aid='2' and vis='Y'

    Thanks Again,
    Justin Sampson



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
  •