在php中发送和获取变量值

时间:2017-05-30 16:48:08

标签: php mysql

我从乘坐MySQL表获取所有游乐设施并将其显示在html表格中。

<?php
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = ''; // Password
$db_name = 'pz'; // Database Name

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
    die ('Failed to connect to MySQL: ' . mysqli_connect_error());  
}

$sql = 'SELECT * 
        FROM ride';

$query = mysqli_query($conn, $sql);

if (!$query) {
    die ('SQL Error: ' . mysqli_error($conn));
}
?>
 <table class="data-table">

        <thead>
            <tr>
                <th>Car Number</th> 
                <th>From</th>
                <th>To</th>
                <th>DATE</th>
                <th>Car Name</th>
                <th>Take This Ride</th>
            </tr>
        </thead>
        <tbody>
        <?php

        while ($row = mysqli_fetch_array($query))
        {

            echo '<tr>
                    <td>'.$row['car_number'].'</td>
                    <td>'.$row['polazak'].'</td>
                    <td>'.$row['odrediste'].'</td>
                    <td>'. date('F d, Y', strtotime($row['datum'])) . '</td>
                    <td>'.$row['car_name'].'</td>
                   <td><a href="ridedetail.php?car_number= $car_number&polazak=$polazak"><button type="button">Take This Ride</button></a></td>
                </tr>';

        }?>
        </tbody>
        <tfoot>

        </tfoot>
    </table> 

现在如果用户单击特定行,我想将该特定行的值带到下一页并显示在该页面上。
谢谢。

1 个答案:

答案 0 :(得分:0)

尝试将<a>放在<tr>

之前
<?php
    $db_host = 'localhost'; // Server Name
    $db_user = 'root'; // Username
    $db_pass = ''; // Password
    $db_name = 'pz'; // Database Name

    $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
    if (!$conn) {
        die ('Failed to connect to MySQL: ' . mysqli_connect_error());  
    }

    $sql = 'SELECT * 
            FROM ride';

    $query = mysqli_query($conn, $sql);

    if (!$query) {
        die ('SQL Error: ' . mysqli_error($conn));
    }
    ?>
     <table class="data-table">

            <thead>
                <tr>
                    <th>Car Number</th> 
                    <th>From</th>
                    <th>To</th>
                    <th>DATE</th>
                    <th>Car Name</th>
                    <th>Take This Ride</th>
                </tr>
            </thead>
            <tbody>
            <?php

            while ($row = mysqli_fetch_array($query))
            {

                echo '<a href="ridedetail.php?car_number='. $row['car_number'].'&polazak='.$row['polazak'].'">
                        <tr>
                        <td>'.$row['car_number'].'</td>
                        <td>'.$row['polazak'].'</td>
                        <td>'.$row['odrediste'].'</td>
                        <td>'. date('F d, Y', strtotime($row['datum'])) . '</td>
                        <td>'.$row['car_name'].'</td>
                       <td><a href="ridedetail.php?car_number='. $roe['car_number'].'&polazak='.$row['polazak'].'"><button type="button">Take This Ride</button></a></td>
                    </tr></a>';

            }?>
            </tbody>
            <tfoot>

            </tfoot>
        </table>