dongliaojing0554 2014-12-18 14:03
浏览 10
已采纳

查看汽车详细信息,而无需为每个结果创建新页面[关闭]

I am new to PHP, and I am making a website about cars. I am using PDO and following the MVC pattern. Now when a user retrieves information about cars on my website, they have the option to 'View more details' of the car and you can imagine that the query the user performs will retrieve 30 cars +, I understand that creating a new page for each one of these cars retrieved would be ridiculous so I am wondering how may I come across creating a new page for that specific car when the 'View more details is clicked'

For example, Facebook doesn't manually create profile pages for each user it just automatically does it when the profile is clicked to view, this is all I have got so far(if it helps):

<?php if(isset($view->CarData2))
  {
    if (count($view->CarData2) > 0){
        foreach($view->CarData2 as $ResultCarData) {
          echo '<div class="row">';
          echo '<div class="col-sm-6 col-md-4">';
          echo '<div class="thumbnail">';
          echo '<img src="" alt=""/>';
          echo '<div class="caption">';
          echo '<h2></h2>';
          echo '<h4 class="colouredTitle">Make: </h4>';
          echo  '<h4>' .$ResultCarData->getMake(). '</h4>';
          echo '<h4 class="colouredTitle">Model: </h4>';
          echo  '<h4>' .$ResultCarData->getModel(). '</h4>';
          echo '<h4 class="colouredTitle">Type: </h4>';
          echo  '<h4>' .$ResultCarData->getType(). '</h4>';
          echo '<h4 class="colouredTitle">Colour: </h4>';
          echo  '<h4>' .$ResultCarData->getColour(). '</h4>';
          echo '<h4 class="colouredTitle">Year: </h4>';
          echo  '<h4>' .$ResultCarData->getYear(). '</h4>';
          echo '<h4 class="colouredTitle">Price: </h4>';
          echo  '<h4>' .$ResultCarData->getPrice(). '</h4>';
          echo   '<button class="btn btn-success" name="view" type="submit" >View more   details</button>';
          echo '</div>';
          echo '</div>';
          echo '</div>';
          echo '</div>';
        }
     }
   else
      {
    echo 'No results found';
      }
  };
?>

Just to summarize what this does, it basically creates these new elements a certain amount of times depending on how many results are retrieved from the users query, it then displays the results in the appropriate areas.

Now my question is, how would I loop new pages when the 'view more details' is clicked? So if the button is clicked create a separate page where the user can view that specific car in more details

  • 写回答

1条回答 默认 最新

  • doufu4333 2014-12-18 14:29
    关注

    You can create a single page that allows you to view the car details (you dont need 30+ pages to create as this single page by passing in a reference id in our case, can query the database), maybe something like this: replace this:

    echo   '<button class="btn btn-success" name="view" type="submit" >View more   details</button>';
    

    with

    echo '<a href="/car-details.php?id=$ResultCarData->getId()">View details</a>
    

    replace the values accordingly.

    And then in your car-details.php (work this around your MVC framework) page, you look for the id parameter ($_GET['id']), query the database for that id and output rest of the data i.e. images, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本