#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    Smile Is this SELECT statement right.


    Each of the statements works when used alone but when I ad the UNION ALL or just the UNION statement something is going wrong. All the variables are preset and working. I have tested everything up to the SELECT statements.

    PHP Code:
    $sql="SELECT * FROM recipes WHERE Cat='$cat'and Eggs='$Eggs' and Fruitose='$Fruitose' and Gluten='$Gluten' and Lactose='$Lactose' and Nuts='$Nuts' and Soy='$Soy' and LowFat='$LowFat' and Diabetice='$Diabetice' and Vegan='$Vegan'
    UNION ALL
    SELECT * FROM recipes WHERE Cat='
    $cat'and Eggs='$Eggs2' and Fruitose='$Fruitose2' and Gluten='$Gluten2' and Lactose='$Lactose2' and Nuts='$Nuts2' and Soy='$Soy2' and LowFat='$LowFat2' and Diabetice='$Diabetice2' and Vegan='$Vegan2'"
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,203
    Rep Power
    4279
    Originally Posted by lparnau
    ... something is going wrong.
    i'm sorry, i am not familiar with the "something is going wrong" error message
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    I am not getting an error message


    Originally Posted by r937
    i'm sorry, i am not familiar with the "something is going wrong" error message
    I am not getting an error message. The script runs all the way through to the ending else "No Records". The problem is when it gets to the SELECT statement it does not seem to be working.

    I have run print_r($result); and all I get is "Resorce#3"

    Its like the SELECT statements never ran?
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,203
    Rep Power
    4279
    Originally Posted by lparnau
    I have run print_r($result); and all I get is "Resorce#3"
    the sql looks okay

    must be your php

    i've moved the thread to the php forum

    you will want to show them more code
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    2
    PHP Code:
    $sql="SELECT * FROM recipes WHERE Cat='$cat' and Eggs='$Eggs' and Fruitose='$Fruitose' and Gluten='$Gluten' and Lactose='$Lactose' and Nuts='$Nuts' and Soy='$Soy' and LowFat='$LowFat' and Diabetice='$Diabetice' and Vegan='$Vegan
    UNION ALL 
    SELECT * FROM recipes WHERE Cat='
    $cat' and Eggs='$Eggs2' and Fruitose='$Fruitose2' and Gluten='$Gluten2' and Lactose='$Lactose2' and Nuts='$Nuts2' and Soy='$Soy2' and LowFat='$LowFat2' and Diabetice='$Diabetice2' and Vegan='$Vegan2'"
    If this is the query, it looks to be fine... It must be your PHP thats wrong.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by lparnau
    I have run print_r($result); and all I get is "Resorce#3"
    Um, you have to actually fetch the rows. The old MySQL functions you're using only return a resource, which you then have to pass to mysql_fetch_assoc() or the various other fetch functions.

    Note that the mysql_() functions are obsolete since about a decade and have officially been deprecated, which means they'll be removed sooner or later. Time to switch to one of the contemporary database extensions.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    Santa Catarina
    Posts
    2
    Rep Power
    0
    Did you try to simulate with firebug? Let the networt section checked like persistence, or the section of console errors to check what's going wrong in the code of your website!
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Guys, everything is working fine. This resource stuff is PHP's way of saying "here's your query result".

    Now lparnau has to learn how to fetch rows from a result set.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo