SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: php mysql query

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2011
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mysql query

    I've made this little query in php:

    PHP Code:
    $category 1;

    $query "SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE CategoryID='$category'"
    The problem is when I write it like that I won't get any output in my mysql_fetch_array.. but if I write it like:

    PHP Code:
    $query "SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE CategoryID=1"
    so I don't get the ID from the variable.. then it shows all the items with categoryID 1..

    Can any see what I'm doing wrong here :S have been sitting with it for some hours now

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Have you checked to make sure that $category actually has something in it?

    Add:
    Code:
    var_dump($category);
    somewhere above that and check what it outputs.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2011
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samanime View Post
    Have you checked to make sure that $category actually has something in it?

    Add:
    Code:
    var_dump($category);
    somewhere above that and check what it outputs.
    get this returned:

    PHP Code:
    int(1


Tags for this Thread

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
  •