donglu7816 2017-03-10 16:00
浏览 23

如何发送产品ID以便在另一个页面上显示?

I'm working on page which consists from database of products.
On the front page you can see every product but with only limited information.
I would like to create secondary page by clicking on Learn more of a product with all information.
Really something widely used in eshops where there is no need to create new page for every product but rather one template which will get information from PHP.

The problem is that I don't know how is this principle working.
I don't even know how it is called so I can search for some tutorial.
Maybe fetching array through products' ID?

For showing products I use:

`

<?php
$db = new PDO("mysql:host=localhost;dbname=cars", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//Query
$cars = $db->prepare("SELECT  car_id, name, price, availability, description FROM cars
");
$cars->execute();
$cars = $cars->fetchAll(PDO::FETCH_ASSOC);
?>

`

And then:

<?php foreach($cars as $car): ?>
          <td>
            <div><img src="<?php echo $car['image'];?>"
            </div>
          </td>
          <td>
            <a href="#">
              <div id="textTable"><strong><?php echo $car['name'];?></strong></a>
                <a href="**what to send here?**" id="learnMore">Learn More..</a>
            </div>
          </td>
          <td>             
                <?php echo $car['availability'];?>                  
          </td>
          <td>
              <strong><?php echo $car['price'];?>€</strong>    
          </td>
        </tr>
      <?php endforeach;?>
  • 写回答

2条回答 默认 最新

  • dpy15285 2017-03-10 16:05
    关注

    One possible solution :

    <a href="/more?id=<?php echo $car['id']; ?>">Learn More..</a>
    

    (I removed the id="learnMore" because an id must appear only once in an HTML page)

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向