【问题标题】:is it possible to css design an element inside an echo是否可以在回声中设计一个元素
【发布时间】:2017-12-21 05:00:26
【问题描述】:

我按照教程制作带有分页的表格,如果可能的话,我想做的是设计链接,(123)在顶部的蓝色背景中,就像添加填充一样,因为它们太狭窄了,颜色:白色等,并将其放在桌子下方。感谢您提供任何帮助和建议。

<div style="overflow-x:auto;">
        <table class="reservations-table">
        <thead>
            <th class="thFirstName">First Name</th>
            <th class="thLastName">Last Name</th>
            <th class="thEmailAddress">Email Address</th>
            <th class="thContactNumber">Contact Number</th>
            <th class="thSpeaker">Speaker</th>
            <th class="thTopic">Topic</th>
            <th class="thLocation">Location</th>
            <th class="thAudience">Audience</th>
            <th class="thCount">Count</th>
            <th class="thTime">Time</th>
            <th class="thDate">Date</th>
            <th class="thAction">Action</th>
        </thead>
    <?php

        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "srdatabase";

        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) 
        {
            die("Connection failed: " . $conn->connect_error);
        } 

        $results_per_page = 10;
        $select= "SELECT * FROM reservations";
        $result = mysqli_query($conn, $select);
        $number_of_results = mysqli_num_rows($result);

        if(!isset($_GET['page']))
        {
            $page = 1;
        }
        else
        {
            $page = $_GET['page'];
        }

        $this_page_first_result = ($page-1)*$results_per_page;

        $sql = "SELECT * FROM reservations LIMIT " . $this_page_first_result . ',' . $results_per_page;
        $result = mysqli_query($conn, $sql);

            while ($row=mysqli_fetch_array($result))
        {
            echo "<tr>
                <td>".$row['firstname']."</td>
                <td>".$row['lastname']."</td>
                <td>".$row['emailaddress']."</td>
                <td>".$row['contactnumber']."</td>
                <td>".$row['speaker']."</td>
                <td>".$row['topic']."</td>
                <td>".$row['location']."</td>
                <td>".$row['audience']."</td>
                <td>".$row['count']."</td>
                <td>".$row['time']."</td>
                <td>".$row['date']."</td>
                <td align='center'><a href='adminControl.php?epr=delete&id=".$row['id']."'>DELETE</a></td>
            </tr>";         
        }

        $number_of_pages = ceil($number_of_results/$results_per_page);

    ?>

    <center>
    <div id="paging-div">

    //paging link 123

    <?php
        for($page=1;$page<=$number_of_pages;$page++)
        {
            echo '<a href="adminControl.php?page=' . $page . '">' . $page . '</a>';
        }
    ?>

【问题讨论】:

  • 首先我在&lt;&lt;thead&gt;里面看不到&lt;tr&gt;,所以需要将当前单元格用&lt;tr&gt;&lt;/tr&gt;及以上包裹起来,加上&lt;tr&gt;&lt;th colspan="12"&gt;123&lt;/th&gt;&lt;/tr&gt;

标签: php html css mysqli


【解决方案1】:

请在&lt;/thead&gt;之后添加&lt;tbody&gt;并关闭&lt;tbody&gt;。旁边请关闭表格标签&lt;/table&gt;

请尝试如下

<div style="overflow-x:auto;">
    <table class="reservations-table">
    <thead>
        <th class="thFirstName">First Name</th>
        <th class="thLastName">Last Name</th>
        <th class="thEmailAddress">Email Address</th>
        <th class="thContactNumber">Contact Number</th>
        <th class="thSpeaker">Speaker</th>
        <th class="thTopic">Topic</th>
        <th class="thLocation">Location</th>
        <th class="thAudience">Audience</th>
        <th class="thCount">Count</th>
        <th class="thTime">Time</th>
        <th class="thDate">Date</th>
        <th class="thAction">Action</th>
    </thead>
    <tbody>
<?php

    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "cktest01";

    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) 
    {
        die("Connection failed: " . $conn->connect_error);
    } 

    $results_per_page = 10;
    $select= "SELECT * FROM reservations";
    $result = mysqli_query($conn, $select);
    $number_of_results = mysqli_num_rows($result);

    if(!isset($_GET['page']))
    {
        $page = 1;
    }
    else
    {
        $page = $_GET['page'];
    }

    $this_page_first_result = ($page-1)*$results_per_page;

    $sql = "SELECT * FROM reservations LIMIT " . $this_page_first_result . ',' . $results_per_page;
    $result = mysqli_query($conn, $sql);

        while ($row=mysqli_fetch_array($result))
    {
        echo "<tr>
            <td>".$row['firstname']."</td>
            <td>".$row['lastname']."</td>
            <td>".$row['emailaddress']."</td>
            <td>".$row['contactnumber']."</td>
            <td>".$row['speaker']."</td>
            <td>".$row['topic']."</td>
            <td>".$row['location']."</td>
            <td>".$row['audience']."</td>
            <td>".$row['count']."</td>
            <td>".$row['time']."</td>
            <td>".$row['date']."</td>
            <td align='center'><a href='adminControl.php?epr=delete&id=".$row['id']."'>DELETE</a></td>
        </tr>";         
    }

    $number_of_pages = ceil($number_of_results/$results_per_page);

?>
</tbody>
</table>


<div id="paging-div">

<!-- paging link 123 -->

<?php
    for($page=1;$page<=$number_of_pages;$page++)
    {
        echo '<a style="color:green" href="adminControl.php?page=' . $page . '">' . $page . '</a>';
    }
?>

   </div>
</div>

【讨论】:

【解决方案2】:

我不确定你想要什么细节,但你当然可以将 CSS style 属性添加到回显的 HTML 中。

一个例子(观看td标签):

echo "<tr>
            <td style='background:#fca;'>".$row['firstname']."</td>
            <td 'background:#cfb;'>".$row['lastname']."</td> 
etc.....

注意:我使用单引号作为标记style 属性值的引号。这些不会干扰您用于回显的双引号。

【讨论】:

  • 我想做的是在这段代码中设置 标签的样式 "for($page=1;$page' . $page . ''; }" 是否可以像您在示例中那样直接设置样式或向其添加 id 以便我可以使用 css 设置样式
  • @Red 你可以像 echo '' . $页。 '';在 Style 中,您可以编写所需的 css。
  • nc。这就是我想做的。但我确定我已经尝试过了,可能是因为我没有先清除我的谷歌缓存。有时我的 css 不工作,当我清除我的历史记录时,再次缓存它的工作。您可以发布您的答案,以便我可以选择它作为写答案
  • @Red 请检查我的答案,他的名字是 MD。阿卜杜勒·哈利姆。我就是那个人。明白了吗?
猜你喜欢
相关资源
最近更新 更多
热门标签