将下拉框和图像链接放在表格中 [英] Put dropdown box and image link in table

查看:138
本文介绍了将下拉框和图像链接放在表格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < html> 
< style>
表{
border-collapse:collapse;
}

table,th,td {
border:1px纯黑色;
border-collapse:collapse;
}
tr:hover {background-color:#f5f5f5}
th,tr {
text-align:center;
}
表格{
margin-left:auto;
margin-right:auto;
宽度:75%;
}
th,td {
padding:15px;
}
< / style>
< / html>
<?php
包含'dbLink.php';

包含'navi.php';


$ sql =SELECT * FROM employee;
$ query =SELECT * FROM employeerole ORDER BY role_id;

$ result = mysqli_query($ link,$ sql);
$ result1 = mysqli_query($ link,$ query);

$ rowcount = mysqli_num_rows($ result);

if($ rowcount> 0)
{?>

如何在每个表格行中输入下拉列表和图片链接?另外,当我运行这个页面时,只有第一行中的数据反映在表格中。其余数据不在表格中。任何修正?

 < table> 
< tr>
雇员ID< / th>
< th>名字< / th>
< th>姓氏< / th>
< th>使用者名称< / th>
雇员角色< / th>
< th>编辑角色< / th>
< th>删除使用者< / th>
< / tr>
<?php
while($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC))
{?>
< tr>
< td><?php echo $ row [id];?>< / td>
< td><?php echo $ row [first_name];?>< / td>
< td><?php echo $ row [last_name];?>< / td>
< td><?php echo $ row [username];?>< / td>
< td><?php echo $ row [role];?>< / td>
< td> //带有来自employeerole表的数据的dropdwon列表< / td>
< td> //图片连结< / td>
< / tr>
< / table>
<?php}?>

<?php
}
}
else
{
echo0 results;
}
?>

截图

解决方案

您混合了 Object Oriented风格&用于写入查询的程序风格。因此,请特别关注写入查询的面向对象程序方式



你在两个方面。前进。

1)面向对象风格

dbLink.php

 < 
$ link = new mysqli(localhost,my_user,my_password,world);
?>

编辑的代码


  $ sql =SELECT * FROM employee; 
$ query =SELECT * FROM employeerole ORDER BY role_id;

$ result = $ link-> query($ sql);
$ result1 = $ link-> query($ query);

$ rowcount = $ result-> num_rows;

if($ rowcount> 0)
{?>
< table>
< tr>
雇员ID< / th>
< th>名字< / th>
< th>姓氏< / th>
< th>使用者名称< / th>
雇员角色< / th>
< th>编辑角色< / th>
< th>删除使用者< / th>
< / tr>
<?php
while($ row = $ result-> fetch_array(MYSQLI_ASSOC))
{?>
< tr>
< td><?php echo $ row [id];?>< / td>
< td><?php echo $ row [first_name];?>< / td>
< td><?php echo $ row [last_name];?>< / td>
< td><?php echo $ row [username];?>< / td>
< td><?php echo $ row [role];?>< / td>
< td>< / td>
< td>< / td>
< / tr>
<?php}?>
< / table>
<?php}

else
{
echo0 results;
}
?>

2)程序风格

dbLink.php

 < 
$ link = mysqli_connect(localhost,my_user,my_password,world);
?>

编辑的代码


  $ sql =SELECT * FROM employee; 
$ query =SELECT * FROM employeerole ORDER BY role_id;

$ result = mysqli_query($ link,$ sql);
$ result1 = mysqli_query($ link,$ query);

$ rowcount = mysqli_num_rows($ result);

if($ rowcount> 0)
{?>
< table>
< tr>
雇员ID< / th>
< th>名字< / th>
< th>姓氏< / th>
< th>使用者名称< / th>
雇员角色< / th>
< th>编辑角色< / th>
< th>删除使用者< / th>
< / tr>
<?php
while($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC))
{?>
< tr>
< td><?php echo $ row [id];?>< / td>
< td><?php echo $ row [first_name];?>< / td>
< td><?php echo $ row [last_name];?>< / td>
< td><?php echo $ row [username];?>< / td>
< td><?php echo $ row [role];?>< / td>
< td>< / td>
< td>< / td>
< / tr>
<?php}?>
< / table>
<?php}

else
{
echo0 results;
}
?>

用户需求:更新的代码

 <? 
$ result = mysqli_query($ link,$ sql);
$ result1 = mysqli_query($ link,$ query);

$ rowcount = mysqli_num_rows($ result);

if($ rowcount> 0)
{?>
< table>
< tr>
雇员ID< / th>
< th>名字< / th>
< th>姓氏< / th>
< th>使用者名称< / th>
雇员角色< / th>
< th>编辑角色< / th>
< th>删除使用者< / th>
< / tr>
<?php
while($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC))
{?>
< tr>
< td><?php echo $ row [id];?>< / td>
< td><?php echo $ row [first_name];?>< / td>
< td><?php echo $ row [last_name];?>< / td>
< td><?php echo $ row [username];?>< / td>
< td><?php echo $ row [role];?>< / td>
< td> //带有来自employeerole表的数据的dropdwon列表< / td>
< td> //图片连结< / td>
< / tr>
<?php}?>
< / table>
<?php
} else {
echo0 results;
}
?>


    <html>
        <style>
            table {
                border-collapse: collapse;
            }

            table,th,td{
                border: 1px solid black;
                border-collapse: collapse;
            }
            tr:hover {background-color: #f5f5f5}
            th,tr {
                text-align: center;
            }
            table {
                margin-left: auto;
                margin-right: auto;
                width: 75%;
            }
            th, td {
                padding: 15px;
            }
        </style>
    </html>
    <?php
include 'dbLink.php';

include 'navi.php';


$sql = "SELECT * FROM employee";
$query = "SELECT * FROM employeerole ORDER BY role_id";

$result = mysqli_query($link, $sql);
$result1 = mysqli_query($link, $query);

$rowcount = mysqli_num_rows($result);

if ($rowcount > 0) 
{?>

How do I input a drop down list and a image link in each table row? Also, when i run this page, only the data in the first row is reflected in the table. The rest of the data is not in the table. Any fixes?

    <table>
            <tr>
                <th>Employee ID</th>
                <th>First name</th>
                <th>Last Name</th>
                <th>Username</th>
                <th>Employee Role</th>
                <th>Edit role</th>
                <th>Delete User</th>
            </tr>
        <?php 
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
        {?>
        <tr>
                    <td><?php echo $row["id"];?></td>
                    <td><?php echo $row["first_name"];?></td>
                    <td><?php echo $row["last_name"];?></td>
                    <td><?php echo $row["username"];?></td>
                    <td><?php echo $row["role"];?></td>
                    <td>//dropdwon list with data from employeerole table</td>
                    <td>//image link</td>
                </tr>
                 </table>
    <?php}?>

<?php 
}
}
else
{
    echo "0 results";
}
?>

Screenshot

解决方案

You have mixed Object Oriented Style & Procedural Style for writing query. So, be particular about Object Oriented or Procedural way of writing query.

I've written a code for you in both way. Go Ahead.

1) Object Oriented Style

dbLink.php

<?
$link = new mysqli("localhost", "my_user", "my_password", "world");
?>

Edited Code

$sql = "SELECT * FROM employee";
$query = "SELECT * FROM employeerole ORDER BY role_id";

$result = $link->query($sql);
$result1 = $link->query($query);

$rowcount = $result->num_rows;

if ($rowcount > 0) 
{?>
    <table>
            <tr>
                <th>Employee ID</th>
                <th>First name</th>
                <th>Last Name</th>
                <th>Username</th>
                <th>Employee Role</th>
                <th>Edit role</th>
                <th>Delete User</th>
            </tr>
        <?php 
    while ($row = $result->fetch_array(MYSQLI_ASSOC)) 
        {?>
        <tr>
                    <td><?php echo $row["id"];?></td>
                    <td><?php echo $row["first_name"];?></td>
                    <td><?php echo $row["last_name"];?></td>
                    <td><?php echo $row["username"];?></td>
                    <td><?php echo $row["role"];?></td>
                    <td></td>
                    <td></td>
                </tr>
    <?php}?>
    </table>
<?php } 

else
{
    echo "0 results";
}
?>

2) Procedural Style

dbLink.php

<?
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
?>

Edited Code

$sql = "SELECT * FROM employee";
$query = "SELECT * FROM employeerole ORDER BY role_id";

$result = mysqli_query($link, $sql);
$result1 = mysqli_query($link, $query);

$rowcount = mysqli_num_rows($result);

if ($rowcount > 0) 
{?>
    <table>
            <tr>
                <th>Employee ID</th>
                <th>First name</th>
                <th>Last Name</th>
                <th>Username</th>
                <th>Employee Role</th>
                <th>Edit role</th>
                <th>Delete User</th>
            </tr>
        <?php 
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
        {?>
        <tr>
                    <td><?php echo $row["id"];?></td>
                    <td><?php echo $row["first_name"];?></td>
                    <td><?php echo $row["last_name"];?></td>
                    <td><?php echo $row["username"];?></td>
                    <td><?php echo $row["role"];?></td>
                    <td></td>
                    <td></td>
                </tr>
    <?php }?>
    </table>
<?php } 

else
{
    echo "0 results";
}
?>

User's Requirement : Updated Code

<?
$result = mysqli_query($link, $sql);
$result1 = mysqli_query($link, $query);

$rowcount = mysqli_num_rows($result);

if ($rowcount > 0) 
{?>
    <table>
        <tr>
            <th>Employee ID</th>
            <th>First name</th>
            <th>Last Name</th>
            <th>Username</th>
            <th>Employee Role</th>
            <th>Edit role</th>
            <th>Delete User</th>
        </tr>
        <?php 
            while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
        {?>
        <tr>
            <td><?php echo $row["id"];?></td>
            <td><?php echo $row["first_name"];?></td>
            <td><?php echo $row["last_name"];?></td>
            <td><?php echo $row["username"];?></td>
            <td><?php echo $row["role"];?></td>
            <td>//dropdwon list with data from employeerole table</td>
            <td>//image link</td>
        </tr>
            <?php }?>
        </table>
<?php 
} else {
    echo "0 results";
}
?>

这篇关于将下拉框和图像链接放在表格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆