【问题标题】:PHP get array value and save it to be displayed in another pagePHP获取数组值并将其保存以显示在另一个页面中
【发布时间】:2016-02-25 11:36:03
【问题描述】:

我有一个显示数组数据的页面。当用户单击显示的其中一张图片时,我需要保存值 $row["Rif"] 因为我需要在另一个页面中显示项目详细信息。

我环顾四周,但似乎 Jquery、Ajax 是唯一可用的解决方案,但我不知道这些。

有没有办法只用 PHP 来实现它?

谢谢!

 <?php
          if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo "<div class='col-md-3 col-sm-6 col-xs-12'>
                            <div class='property-container'>
                              <div class='property-image'>
                                <img src='img/img02.jpg' alt='test theme'>
                                <div class='property-price'>
                                  " . $row["DescCom"] . "<br>
                                  <span>" . "€ ". $row["Pre"] . " </span>
                                </div>
                                <div class='property-status'>
                                  <span>" . $row["Rif"] . "</span>
                                </div>
                              </div>
                              <div class='property-features'>
                                <span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
                                <span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
                                <span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
                              </div>
                              <div class='property-content'>
                                <h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
                                <button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
                              </div>
                            </div>
                          </div>";
                }
            } else {
                echo '0 results';
            }
            $conn->close();
        ?>

【问题讨论】:

  • 为什么不将产品的id 带到下一页并在那里再次获取全部详细信息?
  • 嗨,Fakhruddin,while 循环显示了许多结果,我如何知道要携带哪个 ID?我应该只携带实际点击的那个谢谢
  • 你搞定了吗?

标签: php onclick getvalue


【解决方案1】:

假设数据存储在$row["Rif"]

<?php
          if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo "<div class='col-md-3 col-sm-6 col-xs-12'>
                            <div class='property-container'>
                              <div class='property-image'>

 // if this is the image you can hyper-link it to next page that will carry the id as well.

                              <a href='next_page.php?id=". $row['Rif']."><img src='img/img02.jpg' alt='test theme'></a>
                                <div class='property-price'>
                                  " . $row["DescCom"] . "<br>
                                  <span>" . "€ ". $row["Pre"] . " </span>
                                </div>
                                <div class='property-status'>
                                  <span>" . $row["Rif"] . "</span>
                                </div>
                              </div>
                              <div class='property-features'>
                                <span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
                                <span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
                                <span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
                              </div>
                              <div class='property-content'>
                                <h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
                                <button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
                              </div>
                            </div>
                          </div>";
                }
            } else {
                echo '0 results';
            }
            $conn->close();
        ?>

如果这是图片,您可以将其超链接到带有 id 的下一页。

<a href='next_page.php?id=". $row['Rif']."><img src='img/img02.jpg' alt='test theme'></a>

【讨论】:

  • 嗨,谢谢你,我认为引号有问题,如果我这样离开它就行不通,但即使我改成单引号也不行,不知道怎么做将您的更改嵌入其中谢谢
  • @ChrisA 更新了我的答案。我错过了echo。让我知道它是否有效。
  • @ChrisA 抱歉,我错过了您在 PHP 中实现它。更正了答案。
  • 您好!抱歉打扰,最后一个问题,这个值存储在哪里?我试图在“next_page.php”中回显 $_GET['Rif'] 但它没有设置非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-20
  • 2019-11-27
  • 1970-01-01
  • 2016-11-08
  • 2023-04-11
  • 1970-01-01
相关资源
最近更新 更多