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

    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    5

    Check array for blanks


    I have data as below.
    I can't do this check in the SQL because my server is still on v 4 so I have to do it in PHP code.
    If there is a blank line linked to an order ID but that orderID also has a PayPal entry then it's ok, I want to delete it from the array.
    However, if it hast an OrderID and everything is blank, then I want to echo it.
    In the example below:
    9500 is incorrect
    9503 only has 1 row but is ok
    the rest may have 2 or more rows but as long as 1 row has PayPal in it, then it is ok.
    How can I loop through an array but then delete everything from the array with that ID, and then carry on looping through the array again?

    Code:
    9511	3	PayPal IPN Verified [Completed (Verified; 24.99)]
    9511	3	
    9508	3	PayPal IPN Verified [Completed (Unverified; 3.99)]
    9508	3	
    9507	3	PayPal IPN Verified [Completed (Unverified; 1.99)]
    9507	3	
    9506	3	PayPal IPN Verified [Completed (Verified; 9.49)]
    9505	3	PayPal IPN Verified [Completed (Verified; 9.49)]
    9505	3	
    9504	3	PayPal IPN Verified [Completed (Verified; 7.99)]
    9504	3	
    9503	3	PayPal IPN Verified [Completed (Unverified; 7.99)]
    9502	3	PayPal IPN Verified [Completed (Verified; 1.99)]
    9502	3	
    9501	3	PayPal IPN Verified [Completed (Unverified; 7.99)]
    9500	3	
    9500	3
    Last edited by qwertyjjj; November 5th, 2012 at 04:51 PM.
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,151
    Rep Power
    487
    Perhaps you can loop through the array, creating a second, smaller array which will only hold the "OK" data?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    5
    Originally Posted by badger_fruit
    Perhaps you can loop through the array, creating a second, smaller array which will only hold the "OK" data?
    I'm not sure how to loop through correctly as sometimes the PayPal text is on the first row, sometimes the 2nd, sometimes not at all.

    Code:
    $query = "
    SELECT o.orders_id, o.orders_status, osh.comments
    FROM orders o
    INNER JOIN orders_status_history osh ON osh.orders_id = o.orders_id
    AND osh.orders_status_id =1
    AND o.orders_status =3
    ORDER BY o.orders_id DESC ";
    
    $result = mysql_query($query, $squid_conn_int) or die(mysql_error());
    
    $oid = 0;
    $arrToCheck = array();
    while ($squid = mysql_fetch_array($result, MYSQL_NUM) )
    {
    
    	//echo "<tr>";
    	//echo "<td>".$squid[0]."</td><td>".$squid[1]."</td><td>".$squid[2]."</td>";
    	//echo "</tr>";
    //
    
    if ($oid != $squid[0]
        && $squid[2] == ""
    ) {
    $oid = $squid[0];
    //add into array
    $arrToCheck[] = $oid;
    }
  6. #4
  7. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,151
    Rep Power
    487
    My initial thoughts would be as you loop through, if $squid[2] != "", then do something like $ok_array[$squid[0]] = 1;

    Then at the end of the first loop you should have a new array which will have entries like

    $ok_array[9500] = 1
    $ok_array[9300] = 1
    $ok_array[9511] = 1

    (The key of the $ok_array) would be the ID and the value I've just set to 1 but you could have a counter which increments each iteration of the loop and use that as the key from the first array.

    Does that make sense so far?

    Anyway, once you've cycled through the array, you know which ones were OK and can re-loop through performing a check against $ok_array ....

    Sorry, it's just the first thing that came to mind and it's quite late here so you're lucky I didn't just babble on about how my goldfish are going to survive the winter and if I should feed my cat or not.

    I think I should as she's crawling all over the desk in a "GIVE ME SOME ATTENTION AND FOOD NOW" kind of fashion.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984

IMN logo majestic logo threadwatch logo seochat tools logo