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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts

    remove a certain row from results after query.

    I am looking for a way to remove a certain row from a set of results.

    I grab the product title and price and other details including the `product_id` (int) I am then wanting to remove an item from the results that has a certain `product_id`

    This can not be done easily from the query due to me using OpenCart, and the getProducts file is so much a mess in itself that I am lost as to how or where I do this.

    So think the best way is to remove the item that I do not need from the results set, as this item is already shown elsewhere on the page and do not want to have duplicates on the page.

    I echoed the results array to my page, this is that array, but based on only showing two products, one of which I would need to remove.

    I realised that the product_id is not actually used for the array location but as a sub variable.

    So in the example array below how would I remove say the first or second product
    (the product i am wanting to remove will not be the first item, it could be anywhere in the array)

    The product_id is shown in the first part of the array 1720 or 2057.

    Code:
    array(2) { [1720]=> array(40) { ["product_id"]=> string(4) "1720" ["name"]=> string(26) "aaaaaaaaaaaaaaa" ["description"]=> string(71) "ssssssssssssss" ["meta_description"]=> string(0) "" ["meta_keyword"]=> string(0) "" ["tag"]=> string(0) "" ["model"]=> string(4) "r592" ["sku"]=> string(0) "" ["upc"]=> string(0) "" ["ean"]=> string(0) "" ["jan"]=> string(0) "" ["isbn"]=> string(0) "" ["mpn"]=> string(0) "" ["location"]=> string(0) "" ["quantity"]=> string(3) "100" ["stock_status"]=> string(9) "Pre-Order" ["image"]=> string(25) "data/r592x.jpg" ["manufacturer_id"]=> NULL ["manufacturer"]=> NULL ["price"]=> string(7) "38.9500" ["special"]=> NULL ["reward"]=> NULL ["points"]=> string(1) "0" ["tax_class_id"]=> string(1) "0" ["date_available"]=> string(10) "2013-07-06" ["weight"]=> string(10) "0.15000000" ["weight_class_id"]=> string(1) "1" ["length"]=> string(10) "0.00000000" ["width"]=> string(10) "0.00000000" ["height"]=> string(10) "0.00000000" ["length_class_id"]=> string(1) "0" ["subtract"]=> string(1) "0" ["rating"]=> float(0) ["reviews"]=> int(0) ["minimum"]=> string(1) "1" ["sort_order"]=> string(1) "1" ["status"]=> string(1) "1" ["date_added"]=> string(19) "2013-07-06 14:05:13" ["date_modified"]=> string(19) "2013-07-06 14:05:13" ["viewed"]=> string(1) "4" } [2057]=> array(40) { ["product_id"]=> string(4) "2057" ["name"]=> string(25) "ddddddddddddd" ["description"]=> string(73) "ffffffffffffffffffff" ["meta_description"]=> string(0) "" ["meta_keyword"]=> string(0) "" ["tag"]=> string(0) "" ["model"]=> string(6) "770400" ["sku"]=> string(0) "" ["upc"]=> string(0) "" ["ean"]=> string(0) "" ["jan"]=> string(0) "" ["isbn"]=> string(0) "" ["mpn"]=> string(0) "" ["location"]=> string(0) "" ["quantity"]=> string(3) "100" ["stock_status"]=> string(9) "Pre-Order" ["image"]=> string(27) "data/770400x.jpg" ["manufacturer_id"]=> NULL ["manufacturer"]=> NULL ["price"]=> string(6) "4.5000" ["special"]=> NULL ["reward"]=> NULL ["points"]=> string(1) "0" ["tax_class_id"]=> string(1) "0" ["date_available"]=> string(10) "2013-07-06" ["weight"]=> string(10) "0.10000000" ["weight_class_id"]=> string(1) "1" ["length"]=> string(10) "0.00000000" ["width"]=> string(10) "0.00000000" ["height"]=> string(10) "0.00000000" ["length_class_id"]=> string(1) "0" ["subtract"]=> string(1) "0" ["rating"]=> float(0) ["reviews"]=> int(0) ["minimum"]=> string(1) "1" ["sort_order"]=> string(1) "1" ["status"]=> string(1) "1" ["date_added"]=> string(19) "2013-07-06 14:05:13" ["date_modified"]=> string(19) "2013-07-06 14:05:13" ["viewed"]=> string(1) "4" } }
    Last edited by needsomehelp; 08-29-2013 at 12:58 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    I don't see how this is a MySQL question, at all.

    You have all the data in a PHP array, right? So where does MySQL come into it?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    ah sorry my bad, please can this be moved to where I thought I had posted it, to the PHP section.. I had MySQL heavily on the brain at the time and my fingers got the better of me.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Completely ignore the above post. It's syntactically wrong, serves no purpose relevant to the question, and uses custom function's you won't have anyway.
    What's wrong with simply unsetting it? It doesn't matter that the product_id is a value within the arrays, given what you have here both entries use the associative key as the same product_id anyway. Simply use unset($myResultSetArray[$product_id]); to remove it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Oct 2009
    Posts
    478
    Thanks
    7
    Thanked 3 Times in 3 Posts
    I did try that but for some reason it did not work. I am still trying to remove it.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by needsomehelp View Post
    I did try that but for some reason it did not work. I am still trying to remove it.
    Then you'll need to post some code. Given the only data you have here, you can simply unset from a given key.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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