SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Query returns only partial listing

    My query works fine, except it does not return all the results that I can plainly see exist in the table:

    PHP Code:
    $namesql mysql_query 
        
    ("SELECT ID, ModelName, OwnerName, Approved, Thumb, Date
        FROM racerspotlight
        WHERE (ModelName LIKE '
    $name') AND (Approved LIKE 'y') 
        ORDER BY Date DESC
        "
    ); 
    If I remove the "AND (Approved LIKE 'y')" section then it works perfectly. As it is, it may return one row when two rows meet the conditions. With the AND line gone, it will return both rows. Yet a double-check shows both rows have the same $name and y in their respective fields. I don't get any error messages.

    I need the Approved field so I can accept reader uploads, then I'll change the value from default "n" to "y" if the upload is appropriate.

    The $name is a POST from another page. Here's the code just above the top code:

    PHP Code:
    if (isset($_POST['name'])) 
    {
        
    $name $_POST['name'];
        
    $name strip_tags($name); // REMOVE SYMBOLS 
        
    $name trim($name);       // REMOVE ANY EXTRA WHITE SPACE AT END OF LINE 
        
    $name htmlspecialchars($name);

    Thanks,
    Steve

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried to run the query from the MySQL console to check that it isn't your PHP code that is flawed?

    Also, why aren't you just doing this?
    Code:
    WHERE (ModelName = '$name') AND (Approved = 'y')
    You aren't using any wildcards so you don't need LIKE.

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Oh boy, I see the problem. I was checking the local site for changes, but comparing it with the external database. The local site did not have the external site's Approved fields updated to "y" so it showed only partial results!


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
  •