Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用显示为onclick/checkbox id的MySQL id_Php_Html_Mysql_Checkbox_Onclick - Fatal编程技术网

Php 使用显示为onclick/checkbox id的MySQL id

Php 使用显示为onclick/checkbox id的MySQL id,php,html,mysql,checkbox,onclick,Php,Html,Mysql,Checkbox,Onclick,我正在制作一个需要显示数据库内容的网页,你可以点击它来显示数据库中与该id相关的更多信息,甚至可以将内容旁边的复选框链接到同一个数据库id,这样我就可以根据需要删除帖子,我的显示内容的代码到目前为止工作得很好 但我只是不知道如何将与id相关的id/info链接到复选框或onclick命令 到目前为止,我的代码是: <?php error_reporting(E_ALL); ini_set('display_errors', 1); // Get our database connec

我正在制作一个需要显示数据库内容的网页,你可以点击它来显示数据库中与该id相关的更多信息,甚至可以将内容旁边的复选框链接到同一个数据库id,这样我就可以根据需要删除帖子,我的显示内容的代码到目前为止工作得很好

但我只是不知道如何将与id相关的id/info链接到复选框或onclick命令

到目前为止,我的代码是:

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1);

// Get our database connector
require("includes/conn.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <div id="featured">
    <h2></h2>

    <div>

   <?php 
   error_reporting(E_ALL); 
   ini_set('display_errors', 1); 

    // Grab the data from our people table

    $sql = "SELECT * FROM people ORDER BY ID";
    $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());

    while ($row = mysql_fetch_assoc($result))
    {
        echo "<div class=\"picture\">";
        echo "<p>";

        // Note that we are building our src string using the filename from the database
        echo "<img src=\"content/uploads/" . $row['filename'] . "\" alt=\"\" height=\"219\" width=\"350\" /><br />" . "<br />";
        echo $row['fname'] . " " . "<br />" . "<br />";
        echo "</p>";
        echo "</div>";
    }

    ?>

    </div>

</div>

</body>
</html>

无需复选框,您只需使用锚点包装图像即可

然后,将包含id的url放入查询字符串中:

echo "
<a href='moreinfo.php?id=".$row['id']."'>
    <img src=\"content/uploads/" . $row['filename'] . "\" alt=\"\" height=\"219\" width=\"350\" />
</a>
 <br />" . "<br />";
echo $row['fname'] . " " . "<br />" . "<br />";

谢谢!我马上就要尝试:)我知道MySQL在将来将不受支持,我正在努力,但我想先让一切正常;)但我还有一个问题。。。这也可以用同样的方法做一个复选框,这样我就可以删除一个条目了吗?@FGOD好的,是的,也可以用一个逻辑来做一个复选框,但我认为用收音机更好,因为你的目的是检查一个条目。我需要它来实现两个不同的功能,一个页面显示你给我的内容,以及url部分,另一个是让用户从数据库中删除内容,这需要让用户选择一个或多个要删除的项目/图像,因此我考虑使用带有删除链接的复选框系统来删除所有选中的项目…@FGOD如果是这样的话,您可以,请记住获取并重定向单个复选框值,当然,在另一个主题的“删除”中,您可以收集这些选中的值,然后执行另一个操作。非常感谢,我将研究如何将这些值收集在一起并执行“删除”命令:)(从未使用过数据库,因此这对我来说是全新的,并为我提供了大量的学习时间:))
<?php
$results = array();
if(isset($_GET['id'])) {
    $id = $_GET['id'];
    $db = new PDO('mysql:host=localhost;dbname=DATABASE_NAME', 'username', 'password');

    $sql = 'SELECT * FROM people WHERE `id` = :id';
    $select = $db->prepare($sql);
    $select->bindParam(':id', $id, PDO::PARAM_INT);
    $select->execute();

    $results = $select->fetch(PDO::FETCH_ASSOC);
} else {
    header('Location: go_back_to_index.php');
}

?>

<?php if(!empty($results)): ?>
<h1>Results</h1>
<table cellpadding="10">
    <tr>
        <td>First Name:</td><td><?php echo $results['fname']; ?></td>
    </tr>
    <tr>
        <td>Last Name:</td><td><?php echo $results['lname']; ?></td>
    </tr>
    <tr>
        <td>Photo: </td><td><img src="content/uploads/<?php echo $results['filename']; ?>" alt="profile pricture" /></td>
    </tr>
    <!-- and so on -->
</table>
<?php endif; ?>