Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    31
    Plugin Contributions
    0

    Default Help with SQL query returning multiple rows

    Hi, I have a hopefully simple problem that perhaps someone could help me with. I am running Kuroi's stock by attributes mod and I want a query to select the stock levels for all attributes of a particular product ID.

    So the query I have is for a sample product_id "8" is:
    SELECT products_id, stock_attributes, quantity FROM products_with_attributes_stock
    WHERE (products_id = 8)
    ORDER BY stock_attributes ASC

    Which works fine in phpMyAdmin fine and returns
    9 rows for the 9 attributes I currently have, so far so good.

    However when I put this into php as follows:
    $stock_for_this_prod = "SELECT products_id, stock_attributes, quantity FROM products_with_attributes_stock WHERE products_id = $products_id_current ORDER BY stock_attributes ASC";
    $stock_for_this_prod= $db->Execute($stock_for_this_prod);

    $stock_for_this_prod only ever contains details for the first row / attribute.

    print_r($stock_for_this_prod); gives:
    queryFactoryResult Object ( [is_cached] => [resource] => Resource id #574 [cursor] => 0 [EOF] => [fields] => Array ( [products_id] => 8 [stock_attributes] => 179 [quantity] => 6 ) )

    i.e. only the row for attribute number 179.

    How can I get the rest of the rows to be returned with the $db->Execute funtion?

    Thanks.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Help with SQL query returning multiple rows

    You'll only see the first record unless you loop through your results:

    Code:
    while (!$stock_for_this_prod->EOF) {
      echo 'id=' . $stock_for_this_prod->fields['products_id'] . '; qty=' . $stock_for_this_prod->fields['quantity'];
      $stock_for_this_prod->MoveNext();
    }
    You'll see lots of examples of this in Zen Cart code. A search for MoveNext() should bring back lots of instances to compare against.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Feb 2006
    Posts
    31
    Plugin Contributions
    0

    Default Re: Help with SQL query returning multiple rows

    Thats it :)

    Thank you DrByte - you could not ask for a faster and more helpful reply. Much love for the ZenCart team!

    Cheers.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Help with SQL query returning multiple rows

    You're welcome.

    Feel free to show your appreciation here: http://www.zen-cart.com/index.php?ma...es&pages_id=14
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Replies: 9
    Last Post: 12 Jul 2023, 12:26 AM
  2. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  3. Need help with SQL query. Want to make membership that expires.
    By TecBrat in forum Managing Customers and Orders
    Replies: 1
    Last Post: 18 Jun 2010, 03:43 PM
  4. Help with a sql query
    By batteryman in forum General Questions
    Replies: 21
    Last Post: 3 Oct 2008, 11:12 PM
  5. Help with SQL query
    By Danielle in forum General Questions
    Replies: 3
    Last Post: 9 Jun 2008, 05:24 AM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR