[英]how can I create a product detail page?
i would like to create detail page for my sschoold atabase project. 我想为我的学籍atabase项目创建详细信息页面。 The idea is when you click the added lecture, it should bring a detail page. 想法是,当您单击添加的讲座时,它应该带一个详细信息页面。 I wrote some codes but it didnt work out.. when i clicked the selected lecture nothing happening (href which is in my coursecontroller.php doesnt work). 我写了一些代码,但没有成功..当我单击所选的演讲时,什么都没有发生(我的Coursecontroller.php中的href不起作用)。 My Codes are down below. 我的代码在下面。
Thanks in advance 提前致谢
index.html index.html
<div class="row">
<form method="post" id="add-lecture-form" class="col-xs-6 ajax-form" action="Controller/CourseController.php">
<div class="form-group">
<input type="text" name="title" class="form-control lecture-name-field" placeholder="Please enter a lecture name!!">
</div>
<input type="hidden" id="action" name="action" value="create">
<div class="form-group">
<input type="submit" id="save" class="btn btn-success" value="add a lecture">
</div>
</form>
<div class="col-xs-6"> </div>
<div id="lecture-result"> </div>
</div>
coursecontroller.php coursecontroller.php
function getCourseListAsView() {
$dbConfigObject = new DbConfig;
$dbConnection = $dbConfigObject->getDBConnection();
$query = "SELECT * FROM courses";
$search_query = mysqli_query($dbConnection, $query);
$listview = "<ul class='course-list'>";
while ($row = mysqli_fetch_array($search_query)) {
//title column in db
$listview .= '<li class="course-list-element">'
. '<a class="detail-link" data-toggle="modal" data-target="" data-id="' . $row['id'] . '" href="Controller/detail.php">' . $row['title'] . '</a>'
. '<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-primary load-edit-form-button" data-id="' . $row['id'] . '" data-title="' . $row['title'] . '" data-action="edit" href="Controller/CourseController.php">edit</button>'
. '<button type="button" class="btn btn-danger action-button" data-id="' . $row['id'] . '" data-action="delete" href="Controller/CourseController.php">delete</button>'
. '</li>';
}
$listview .= "</ul>";
echo $listview;
}
detail.php detail.php
foreach($_GET as $key=>$value){
echo $key, ' => ', $value, "<br/>n";
}
$id = $_GET['id'];
if($id) {
echo '<p/>ID: ', $id, "<br/>n";
}
else {
echo '<p>No ID parameter.</p>';
}
custom.js custom.js
$('.detail-link').click(function(){
window.location = 'Controller/detail.php';
});
option One: Coursedetail.php 选项一: Coursedetail.php
function getCourseListAsView() {
$dbConfigObject = new DbConfig;
$dbConnection = $dbConfigObject->getDBConnection();
$query = "SELECT * FROM courses";
$search_query = mysqli_query($dbConnection, $query);
$listview = "<ul class='course-list'>";
while ($row = mysqli_fetch_array($search_query)) {
//title column in db
$listview .= '<li class="course-list-element">'
. '<a class="detail-link" data-toggle="modal" data-target="" data-id="' . $row['id'] . '" href="Controller/detail.php?id=<?php echo $row['id']; ?>">' . $row['title'] . '</a>'
. '<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-primary load-edit-form-button" data-id="' . $row['id'] . '" data-title="' . $row['title'] . '" data-action="edit" href="Controller/CourseController.php">edit</button>'
. '<button type="button" class="btn btn-danger action-button" data-id="' . $row['id'] . '" data-action="delete" href="Controller/CourseController.php">delete</button>'
. '</li>';
}
$listview .= "</ul>";
echo $listview;
}
Option two : Don't change the course detail.php. 选项二:不要更改课程detail.php。
In custom.js file 在custom.js文件中
$('.detail-link').click(function(e){
e.preventDefault();
var id = $(this).data("id");
window.location = 'Controller/detail.php?id='+id;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.