Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    96
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Question about returning unique rows

    Hello,

    I've got a question about returning unique rows with php from the database.

    Lemme first place my code:

    PHP Code:
    $sizecat=mysql_real_escape_string($_GET[sizecat]);
    $finalsize=$_GET[finalsize];
    $color=$_GET[color];
    $material=$_GET[material];
    $size=$_GET[size];

    $finalQuery=mysql_query("SELECT DISTINCT thumb_size, size, totalsize, Info, material, thumb_material, finalsize, color FROM `Folders` WHERE `sizecat`='{$sizecat}' AND `finalsize`='{$finalsize}' AND `color`='{$color}'  AND `material`='{$material}';"); 
    This part completely works and I got unique rows (no double entries are shown). However, the query returns four rows, instead of only one. Therefore, I need to add this:

    PHP Code:
     AND `size`='{$size}' 
    in the select query at the end. But then the query doesn't return any row anymore.... If I do the same in sql database, I get the one row I am looking for (with the added variables of course). Now this is part of a switch and this is the final step of 5 total steps. The first four variables (sizecat, finalsize, color and material) are called during every step starting with the first one and adding one with every next step.

    So it seems logically that php can recall the selected variables. The last one that I need to add isn't called anywhere before, except for the first step. If I call these at the other steps, I don't get one row as a result.... I get more results shown.

    The thing is, that there are more sizes, but only one color. So during the third step (which is color), I only want one result.... But if I add the last part to get the size, I get more results are there are three different sizes and only one color.

    But if I don't add the size part there, php doesb't know which size it must return and thus the query returns empty.

    Does anybody know how I can fix this? thx in advace!!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Does your call to mysql_query() ever fail? That is to say, does it every return FALSE?

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    96
    Thanks
    1
    Thanked 2 Times in 2 Posts
    No it works. Though only sometimes it is empty (no results found). But it completely works. Why?


  •  

    Posting Permissions

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