Jump to content

Emmet89

New Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by Emmet89

  1. Man your totally right! 

    But, I just changed the requirements so 5609 hasnt hit enough visits and it still isnt working as expected!

    ID of cat : 5609
    Visits required per day : 6
    ID of cat : 23641
    Visits required per day : 5

    Array ( [0] => 5609 [1] => 23641 )

    23641 has not visited enough

     

     

  2. Its giving me an output of : 

    23641 has not visited enough

     

    From this: 

    foreach(getTodaysVisits($device_id) as $rfid){
        foreach($rfid as $key=> $read){
        //echo $key."<br>";
        //$i=0;
         if(array_search($key,$rifdid) && $read < $visitsneeded) {
            echo $key." has not visited enough"; 
           // $i++;
       }

    Am I not using the array_search correctly?

  3. Yes thats exactly it, here is the output when i echo both out :

    Array
    (
        [0] => 5609
    
        [1] => 23641
    
    )
    23641
    5609

    But when I implement the Array_search it still isnt looping into the next value 

    foreach(getTodaysVisits($device_id) as $rfid){
        foreach($rfid as $key=> $read){
        //echo $key."<br>";
        //$i=0;
         if(array_search($key,$rifdid) && $read < $visitsneeded) {
            echo $key." has not visited enough"; 
           // $i++;
       }
    
    }
    }

    Ive no idea why it wouldnt be going into the next value?

  4. hey thanks for the feeback 

     

    I've implemented as follows : 

    $i=0;
    
    foreach(findCustomAlerts($customerid) as $key=>$value){
    echo "ID of cat : ".$rifdid[$i++] = $value['Catid']."<br>";
    echo "Visits required per day : ".$visitsneeded= $value['Visits required']."<br>";
    
    
    foreach(getTodaysVisits($device_id) as $rfid){
    foreach($rfid as $key=> $read){
    $i=0;
    if($key ==$rifdid[$i++] && $read < $visitsneeded) {
    echo $key." has not visited enough";
    }
    }
    
    }
    
    }
    
    

     

    But now instead of picking up the last item its only picking up the first item - have i implemented the code incorrectly?

    Output : 

    ID of cat : 5609
    Visits required per day : 3
    ID of cat : 23641
    Visits required per day : 5
    5609 has not visited enough

     

    When I use the array_search its not picking up any of the items from the array at all. 

  5. Sorry man! Didnt check the formatting rules before I posted - will be sure to do that next time. 

    I can see now what you mean by the $rfidid - that is definately not what I need as I need to access each of the $rfidids that are in the list. 

    How would the best way in going  about combining the two so I can gain access to both ids?

  6. Hi I am new to PHP and I am having an issue with a foreach loop combined with an if statement, basically the if statement is getting the data from the first result in the foreach but not getting the second result, I have tried implement a count by using a variable to iterate but it isnt working: 

    Code as follows:

    foreach(findCustomAlerts($customerid) as $key=>$value){
    
        echo "ID of cat : ".$rifdid = $value['Catid']."<br>";
    
        echo "Visits required per day : ".$visitsneeded= $value['Visits required']."<br>";
    
    }
    
    foreach(getTodaysVisits($device_id) as $rfid){
    
        foreach($rfid as $key=> $read){
    
            if($key ==$rifdid && $read < $visitsneeded) {
    
                echo"<br>". $key." has not visited enough";
    
            }
    
        }
    
    }

    Ouput is : 

    ID of cat : 5609
    Visits required per day : 3
    ID of cat : 23641
    Visits required per day : 5

    Array ( [rfid_id] => Array ( [23641] => 1 [5609] => 3 ) ). -------> this is the array data 


    23641 has not visited enough

    -----------------------------------------------

    How can I get the loop to iterate to the next value? 

     

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.