douci1196 2017-06-01 09:54
浏览 7

PHP MYSQL“更多信息”按钮

I have a question:

In PHP, HTML and MySQL I have made an overview of products (data from database) Now each product in this list has a more info button. I want, when I click more info, that a new page is opened and that page should show more info about that product. How do I make it work that it only shows the info of that particular product?

This is the current code of the table with the overview:

    <div class="col-xs-2">
                        </div>
                        <div class="col-xs-4">
                            <h4 class="product-name"><strong> Producten</strong></h4><h4><small></small></h4>
                        </div>
                        <div class="col-xs-6">
                            <div class="col-xs-6 text-right">
                                <h6><strong>Datum binnenkomst</strong></h6>
                            </div>
                            <div class="col-xs-4">
                                <h6><strong>Datum uitgave</strong></h6>
                            </div>
                            <div class="col-xs-2">
                            </div>
                        </div>
                    </div>
                    <hr>
<?php 
include("connection.php");
$sql = "SELECT * FROM bedrijven";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo'
                    <div class="row">
    <div class="col-xs-2"><img class="img-responsive" style="max-height:80px;" src="' . $row["KVK"] . '">
                        </div>
                        <div class="col-xs-4">
                            <h4 class="product-name"><strong> '. $row["Bedrijfsnaam"] .' </strong></h4><h4><small>'. $row["Klantnummer"] .'</small></h4>
                        </div>
                        <div class="col-xs-6">
                            <div class="col-xs-6 text-right">
                                <h6><strong>'. $row["BStraatnaam"] .'</strong></h6>
                            </div>
                            <div class="col-xs-4">
                                <h6><strong>'. $row["BHuisnummer"] .'</strong></h6>
                            </div>
                            <div class="col-xs-2">
                                <a href="Moreinfo.php"> <button type="button" class="btn btn-link btn-xs">
                                    More info
                                </button></a>
                            </div>
                        </div>
                    </div>
                    <hr>';
    }
} else {
    echo "0 results";
}
$conn->close();?>

I hope someone would help me.

It would be nice to learn more and new things;)

  • 写回答

1条回答 默认 最新

  • doujiang3997 2017-06-01 10:09
    关注

    If you want to split up results only print out what you want to show. You can do selective queries with LIMIT (for a range) or just make sure you only get one result usually done by using a unique identifier (an auto-incremented ID field) and WHERE id = 1.

    And in PHP we can use $_GET['page'], to get the page parameter from an url like:

    domain.com/somepage?page=2
    

    However remember that this is easily edited by the end user in the location bar and thus should be properly handled in PHP before using it in a SQL query to avoid SQL injection. It be checking with PHP's is_number or using something like prepared statements

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。