简体   繁体   English

打开另一个页面并用php发送数据?

[英]Open another page and send data in php?

I'm developing a simple online portfolio website for my final project. 我正在为我的最终项目开发一个简单的在线投资组合网站。 I have a page to show all design stored in database. 我有一个页面来显示存储在数据库中的所有设计。 This is the template of a item, 这是项目的模板,

+---------------------+
+                     +
+                     +
+       image         +
+                     +
+                     +
+                     +
+---------------------+
+      Title          +
+                     +
+---------------------+

This is the code that i used to load all items from databse. 这是我用来从数据库加载所有项目的代码。

<?php
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $title = $row['title'];
        $image = $row['image'];
        $designer = $row['designer'];
        $views = $row['views'];
        $likes = $row['likes'];
        $price = $row['price'];
?>
    <div class = "col-md-3 col-sm-6"> <div class = "wow fadeInUp animated portfolio-item" data-wow-duration = "500ms" data-wow-delay = "600ms">
        <div class = "img-wrapper">
            <img src = "<?php echo $image; ?>" class = "img-responsive" alt = "" ></div>
                <div class = "portfolio-item-text"><h4><a href = "preview.php?title">
                    <?php echo $title; ?>
                    </a>
                    </h4>
                    <p id = "portfolio-subtitle">
                    by <?php echo $designer; ?>
                    </p>
                    <div class="row" style="margin-top:10px;">
                        <div class="col-md-3" style="float:left;">
                            <h6><?php echo $price; ?></h6>
                        </div>
                        <div class="col-md-7" style="float:right;">
                            <div class="portfolio-icons">
                                <ul class="list-inline">
                                    <li><i class="fa fa-eye"></i> <?php echo $views; ?></li>
                                    <li><i class="fa fa-thumbs-o-up"></i> <?php echo $likes ?></li>
                                </ul> 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <?php
}
?>

I need to open another page to preview each design. 我需要打开另一个页面来预览每个设计。 So i used $_SESSION to bring data to my preview page inside the while loop. 所以我用$ _SESSION在while循环中将数据带到预览页面。

$_SESSION['id'] = $row['design_id'];
$_SESSION['title'] = $row['title'];

but it only preview the last item. 但只会预览最后一个项目。 How can i solve this. 我该如何解决。

You need to change the link 您需要更改链接

<a href="preview.php?title"><?php echo $title; ?> </a>

to something like this: 像这样:

<a href="preview.php?id=<?= $row['design_id'] ?>"><?php echo $title; ?></a>

Then you can get in the preview.php file the id with $_GET['id'] . 然后,您可以在Preview.php文件中获得带有$_GET['id'] But don't forget to check if it is a number before usage. 但不要忘记在使用前检查它是否为数字。 (is_numeric() or int_val()) (is_numeric()或int_val())

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM