PHP Arrays

Discussion in 'PHP' started by mich21, Feb 17, 2008.

  1. #1
    I have an array of id's(array1) each with corresponding hits(array2).
    Im using an imploded array1 to select ids from a table.

    like so:
    select * from table where id in $array1;


    Now i want to add the corresponding hits of each id in the query result.

    The problem is that the result is automatically ordered by id ASC. So when i add my hits to the result, they do not match with the id's. How can i achieve this? Thanks in advance :)
     
    mich21, Feb 17, 2008 IP
  2. 00johnny

    00johnny Peon

    Messages:
    149
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I like the idea of using one array so its more organized
    ie
    array(
    id => value
    );
    PHP:
    is a typical setup that I use.
    then you can loop through your results and find a match, sure this is slow but.. oh well

    
    foreach($result as $r) {
      foreach($hitArray as $h) {
         if($r['id'] == $h['id']) {
          // oh cool!, now $r is the row that has all your data and $h is your hit value
          }
    }
    
    PHP:
     
    00johnny, Feb 18, 2008 IP
  3. mich21

    mich21 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks a lot! But I forgot to add that i'm using paging:

    select * from table where id in $array1 $LIMIT;
    $LIMIT = $LIMIT($a,$b);

    I made it work without paging though.. :)
     
    mich21, Feb 18, 2008 IP