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 8 of 8
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I record results in an array ?

    Hi,

    I am running through a for loop and want to record the results
    in an array.

    The loop compares 2 files together and I want to record
    three elements of data plus the file numbers. ( so that's five elements )

    There will be approx 100 files to compare together.

    so 100 * 100 = 10,000
    less 100 because we don't compare the files with themselves.

    So total of 9,900 lines in the array.


    So if I have
    PHP Code:
    $results = array();

    for (
    $art1 0$art1 <= $art_cnt$art1++) {
      for (
    $art2 0$art2 <= $art_cnt$art2++) {

      if( 
    $art1 != $art2 ) {
        
    Here I need to record this data:
        
    $art1$art2$data1$data2$data3
       
    }
     }

    Is this a multi-dimensional array ?

    Thanks for any help.


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    PHP Code:
    $results = array();

    for (
    $art1 0$art1 <= $art_cnt$art1++) {
      for (
    $art2 0$art2 <= $art_cnt$art2++) {

      if( 
    $art1 != $art2 ) {
        
    //Here I need to record this data:
        
    $results[]=array($art1$art2$data1$data2$data3);
       }
     }

    yes its a multi-dimensional array, the bigger question is what do you want to do with it since that may give us a clue on the best way forward ... what exactly do you mean by record ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Yes

    I was going to add that but didn't want to muddle things up

    So after the loops have finished, I want
    to display all the results in a table:
    Here is one table that is showing $data1 for
    each combination.

    ( I have just used 10 files )



    Well you get the idea

    There will be two other tables to show
    $data2 and $data3

    - If you can suggest to l me the best way to display these tables
    that be very helpful

    thanks.



    .
    Last edited by jeddi; 10-11-2013 at 12:17 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    New Coder
    Join Date
    Sep 2013
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try out the below code:

    while($row = mysql_fetch_assoc($result)){
    $art1[] = $row;
    }
    echo art1_encode($art1);

    If you switched to MySQLi you could do:

    $art1 = mysqli_fetch_all ($result, MYSQLI_ASSOC);
    echo art1_encode($art1 );

    Hope this helps.

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks,
    but I am not recording the results in
    a database they are just held in the $results array,
    so I need to display them from that.

    How would I create the table in my previous post
    from an array like this:
    $results[]=array($art1, $art2, $data1, $data2, $data3);

    ( just using $art1, $art2, $data1) from the array. ?

    Thanks.


    .
    Last edited by jeddi; 10-12-2013 at 01:41 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #6
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Can anyone help me on this ??


    Thanks.



    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    sorry, really not getting exactly what you want to do or what exactly you are comparing, I understand it makes sense to you but its not translating here.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    OK - lets ignore 2 of the data points and just consider one data point
    for each comparison.

    In the table I showed, I am comparing two strings $art1 with $art2
    and it gets a result ( $data1 )

    So we add these to the array ($art1 ,$art2, $data1)

    Next the script compares $art1 with $art3
    and it gets a result ( $data1 )
    So we add these to the array ($art1 ,$art3, $data1)

    Next the script compares $art1 with $art4
    and it gets a result ( $data1 )
    So we add these to the array ($art1 ,$art4, $data1)

    etc etc.

    Last it compares $art100 with $art99
    and it gets a result ( $data1)
    So we add these to the array ($art100 ,$art99, $data1)

    So I end up with an array with a total of 9,900 lines.
    $results[]=array($art1, $art2, $data1);


    How do I walk through the array $results[] to produce the table like in my
    example ( where I just show first ten $art1 - $art10 comparing
    with $art1 - $art10 ) ??


    Hope that makes it more clear

    Thanks.



    .


    Hope
    Last edited by jeddi; 10-17-2013 at 09:32 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


  •  

    Posting Permissions

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