简体   繁体   English

如何使用 PHP/MYSQL 从我的项目页面在我的项目详细信息页面中显示一个项目

[英]How to display one item in my item details page from my item page using PHP/MYSQL

Okay So Here I'm trying to link a Item details page to a Item page, I have successfully done so however when I click on an item all the item details are showing up I would like to know how to Only Display one item on the item details page for the corresponding id.好的,所以在这里我试图将一个项目详细信息页面链接到一个项目页面,我已经成功地做到了这一点,但是当我点击一个项目时,所有项目详细信息都显示出来我想知道如何只显示一个项目相应 id 的项目详细信息页面。 I know I'm missing some code (think its a GET or POST variable) to complete the link if anyone can help it will be much appreciated thanks alot我知道我缺少一些代码(认为它是 GET 或 POST 变量)来完成链接,如果有人可以提供帮助,将不胜感激,非常感谢

Heres my code这是我的代码

item.php项目.php

            <div class="rone">
            <?php
        $conn = new mysqli("xxx", "xxx", "xxx", "xxx");
        if ($conn->connect_error) {
            die("Connection Failed!" . $conn->connect_error);
        }
        ?>
            <?php
                $stmt = $conn->prepare('SELECT * FROM items');
                $stmt->execute();
                $result = $stmt->get_result();
                while ($row = $result->fetch_assoc()):
            ?>

            <div class="col-4">
                <a href="item-details.php?id=<?= $row['id'] ?>"><img src="<?= $row['itemimage'] ?>"></a>
                <h4"><?= $row['item_name'] ?></h4>
           </div>
           
            <?php endwhile; ?>                                                           
            </div>

item-details.php项目详细信息.php

            <div class="rone">
            <?php
        $conn = new mysqli("xxx", "xxx", "xxx", "xxx");
        if ($conn->connect_error) {
            die("Connection Failed!" . $conn->connect_error);
        }
        ?>
            <?php
                // UPDATE when this is done it does not work it gives the following error:: Uncaught Error: Call to a member function execute() on bool in C:\xampp\htdocs\assignment1\item-details.php:111 Stack trace: #0 {main} thrown in and the line 111 they referring to is this $stmt->execute(); ------ But if I do this //$id = $_GET['id'];
                //$stmt = $conn->prepare('SELECT * FROM items WHERE id = 1') the code will work just fine but it will only show item 1 regardless of which item I click. Hope this helps 👍

                $id = $_GET['id'];
                $stmt = $conn->prepare('SELECT * FROM items WHERE id = $id');
                $stmt->execute();
                $result = $stmt->get_result();
                while ($row = $result->fetch_assoc()):
            ?>
            <div class="col-2">
                <img src="<?= $row['itemimage'] ?>" width="100%" id="ItemImg">                
            <?php endwhile; ?>
            </div>
            <div class="col-2">
                <h1><?= $row['item_name'] ?></h1>
            </div>
    </div>

the names of my rows are: id , itemimage, item_name and in time to come I will add other attributes And the main table is items.我的行的名称是: id 、 itemimage、 item_name 并且我会及时添加其他属性并且主表是项目。

I see $id ' ' );我看到 $id ' ' ); Remove one of that ' to {$id}');删除其中一个 ' 到 {$id}');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将信息从项目传递到 PHP 中的项目显示页面 - Pass information from item to a item display page in PHP 使用PHP和MySQL从购物车中删除商品 - Deleting an item from my shopping cart using PHP and MySQL 每页一个测验项目(php / mysql测验程序) - One quiz item per page (php/mysql quiz program) 如何使用php从MySQL数据库中打印选定的列表项? - How do I print a selected list item from my MySQL database using php? 无法显示查询结果中的一项-PHP / MySQL - Not able to display one item from query result - PHP/MySQL 使用jquery和jsp(或php)显示用户在html页面中单击该项目的特定项目的信息 - Display information of particular item the user clicks on the item in html page using jquery and jsp(or php) 如何将链接项目添加到 WooCommerce 我的帐户菜单中的另一个页面 - How to add a linked item to another page in WooCommerce My Account menu 在我的HTML / PHP页面上选择下拉项时,如何在jQuery(AJAX)中检测到? - How do I detect in jQuery (AJAX) when a drop down item is selected on my HTML/PHP page? 如何在PHP中循环时跳过一项以从数据库显示 - how to skip one item to display from database while loop in php 如何使用SimpleXML将rss提要项保存为PHP中的单个页面 - How to save rss feed item as single page in PHP using SimpleXML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM