如何从数组中获取组合值?

时间:2017-10-28 10:09:01

标签: php html html-table

数组:

<!DOCTYPE html>
<html>
    <head>
        <style>
            table {
                font-family: arial, sans-serif;
                border-collapse: collapse;
                width: 100%;
            }

            td, th {
                border: 1px solid #dddddd;
                text-align: left;
                padding: 8px;
                text-align: center;
            }
            .btn {
                border: none;
                color: white;
                padding: 7px 14px;
                font-size: 10px;
                cursor: pointer;
            }
            a {
                text-decoration:  none;
            }

            .success {background-color: #4CAF50;} /* Green */
            .success:hover {background-color: #46a049;}

        </style>
    </head>
    <body>

        <table>
            <tr>
                <th>Date</th>
                <th>Def</th>
                <th>Delode</th>
                <th>Id</th>
            </tr>
            <?php
            $phase = $foodStyle = $workout = '';
            $last_key = end(array_keys($result));
            foreach ($result as $key => $value) {
                ?>
                <tr>
                    <td><?= $value['day_date'] ?></td>

                    <!-- For Phase HTML-->
                    <?php if ($value['phase'] == null) { ?>
                        <td>-</td>
                    <?php } else if ($phase != $value['phase']) { ?>
                        <td style="border-bottom: none;">
                            <a href="http://localhost/grid/test.php?phase=<?= $value['phase'] ?>&start-data=<?= $value['day_date'] ?>&end-date="><?= $value['phase'] ?></a>
                        </td>    
                        <?php
                        $phase = $value['phase'];
                    } else {
                        ?>
                        <?php if ($key == $last_key) { ?>
                            <td style="border-top: none;"></td>
                        <?php } else { ?>
                            <td style="border: none;"></td>
                        <?php } ?>    
                    <?php } ?>  

                    <!-- For FoodStyle HTML-->    
                    <?php if ($value['foodstyle'] == null) { ?>
                        <td>-</td>
                    <?php } elseif ($foodStyle != $value['foodstyle']) { ?>
                        <td style="border-bottom: none;">
                            <a href="http://localhost/grid/test.php?foodstyle=<?= $value['foodstyle'] ?>&start-data=<?= $value['day_date'] ?>&end-date="><?= $value['foodstyle'] ?></a>
                        </td>    
                        <?php
                        $foodStyle = $value['foodstyle'];
                    } else {
                        ?>
                        <?php if ($key == $last_key) { ?>
                            <td style="border-top: none;"></td>
                        <?php } else { ?>
                            <td style="border: none;"></td>
                        <?php } ?>
                    <?php } ?>    

                    <!-- For Workout Id HTML-->  
                    <?php if ($value['workout_id'] == null) { ?>
                        <td>
                            <a href="http://localhost/grid/test.php?workout_id=<?= $value['workout_id'] ?>&start-data=<?= $value['day_date'] ?>&end-date="> <button class="btn success">  + </button> </a> 
                        </td>
                    <?php } elseif ($workout != $value['workout_id']) { ?>
                        <td style="border-bottom: none;">
                            <a href="http://localhost/grid/test.php?workout_id=<?= $value['workout_id'] ?>&start-data=<?= $value['day_date'] ?>&end-date="><button class="btn success"> <?= $value['workout_id'] ?></button></a> 
                        </td>    
                        <?php
                        $workout = $value['workout_id'];
                    } else {
                        ?>
                        <?php if ($key == $last_key) { ?>
                            <td style="border-top: none;"></td>
                        <?php } else { ?>
                            <td style="border: none;"></td>
                        <?php } ?>
                    <?php } ?>
                </tr>
            <?php } ?>
        </table>
    </body>
</html>

HTML:

import org.assertj.core.api.Assertions;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class TestClassSample {
    private List<String> data;

    @Factory(dataProvider = "getDataForInstances")
    public TestClassSample(List<String> data) {
        this.data = data;
    }

    @BeforeMethod
    public void beforeMethod(Object[] parameters) {
        System.err.println("Printing Parameters before running test method " + Arrays.toString(parameters));
    }

    @Test(dataProvider = "getData")
    public void testMethod(String text) {
        System.err.println("Printing Parameters when running test method [" + text + "]");
        Assertions.assertThat(text).isNotEmpty();
    }

    @AfterMethod
    public void afterMethod(ITestResult result) {
        System.err.println("Printing Parameters after running test method " + Arrays.toString(result.getParameters()));
    }

    @DataProvider(name = "getData")
    public Object[][] getData() {
        //This data provider simulates the iterations that every test method has to go through based on
        //the outer data provider viz., "getDataForInstances()"
        Object[][] iterationData = new Object[data.size()][1];
        for (int i = 0; i < data.size(); i++) {
            iterationData[i] = new String[]{data.get(i)};
        }
        return iterationData;
    }

    @DataProvider(name = "getDataForInstances")
    public static Object[][] getDataForInstances() {
        //This data provider simulates data being read from excel, wherein it would return the number of
        //iterations that every test method should go through.
        return new Object[][]{
                {Collections.singletonList("Java")},
                {Arrays.asList("TestNG", "JUnit")},
                {Arrays.asList("Maven", "Gradle", "Ant")}
        };
    }
}

输出:

enter image description here

根据我希望href链接的图像,当我单击“Def”列的“定义”行并且所有列都相同时,href链接如http://localhost/grid/test.php?phase=Definition&start-data=2017-10-27&end-date=2017-10-29。此外,我希望从所有组合列的中心排'定义'。

任何帮助都将不胜感激。

0 个答案:

没有答案