Hi,

I have a file that looks like this:

#gc: Ian
eth0,1000,1100,1200,1300,1400
eth1,10,100,200
eth2,3000,3100,3200,3300

Okay, the numbers after the ethx are not static, there can be more and there
can be less depending on what the user selects.

Now my problem, I have a list of numbers that they can choose using
checkboxes, and I now want the checkboxes to be ticked if  the number+ethx
appear in the file.

How would I go about reading the file and then finding out if the
number+ethx are there ? I have tried something like this:
[code]
$file=file("/ian/testing.file");        //Load the file into array
unset($file[0]);                        //Remove the first #gc line
foreach($file as $line){                // Run through each array line
        $array[]=explode(",", $line);   //Separate each line in key/variable.
}
[/code]
This gives me an output something like this (Dont take note of numbers, they
change per user:
Array
(
    [0] => Array
        (
            [0] => eth0
            [1] => 1100
            [2] => 1200
            [3] => 1300
        )
    [1] => Array
        (
            [0] => eth1
            [1] => 1100
            [2] => 1200
            [3] => 1300
        )
    [2] => Array
        (
            [0] => eth2
            [1] => 40
            [2] => 50
            [3] => 60
        )
)

Okay, now for the difficult part. I run a global foreach($eth as $whatever)
to run through each eth and then another foreach loop within that to
determine the numbers for each eth. Great, that works no problem. Now when
it comes to the part of comparing that the eth+number are in the same array
(to determine wether the checkbox must be ticked or not) I cant figure out
how todo it. I have tried various options like.
[code]
foreach($file as $line){
        if((in_array("1100", $line)) and (in_array("eth0", $line))){
                echo "Found eth0 and 1100 in array. Checkbox can be checked";
        }else{
                echo "Not found";
        }
}
[/code]

Now obviously, the first line should be returned as true, as eth0 and 1000
are in the same array. But it doesnt. It returns false the whole time. The
problem is that the ethx+number must be in the SAME array not only in the
whole global array, otherwise checkboxes that show up ticked are actually
not going to be in the file. Oh the page where you select is layed out
something like the diagram below. (Note there can be more numbers per ethx
these are just examples.

eth0
1000                    []
1100                    []
1200                    []
1300                    []
1400                    []
6000                    []
6500                    []
2300                    []
eth1
40                      []
50                      []
60                      []
1000                    []
eth2
1100                    []
1200                    []
1300                    []

I hope I have not confused you now, please ask if something isnt clear.

Thanks a million for the help.

Ian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to