- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在类别中每页显示一个视频,并使用按钮下一个/上一个用户可以导航到下一个或上一个 id
在数据库中。问题是,当我在该类别的第一个视频上时,按钮 previous
仍然在那里,我可以转到前一个 id,这是另一个类别。与按钮 next
相同。当用户观看该类别的最后一个视频时,下一个按钮仍然存在,可以单击它,这将从数据库加载下一个 ID(下一个类别)。
if(isset($_GET['video_id']) && is_numeric($_GET['video_id']) && isset($_GET['video_cat_id']) && is_numeric($_GET['video_cat_id'])){
$video_id = $_GET['video_id'];
$video_cat_id = $_GET['video_cat_id'];
// get next picture id
$result = $pdo->prepare('SELECT video_id FROM video WHERE video_id > :video_id ORDER BY video_id ASC LIMIT 1');
if($result){
$result->execute(array(':video_id' => $video_id));
//$result->execute(array(':video_cat_id' => $video_cat_id));
if (($row = $result->fetch()) !== FALSE) {
$next_id = $row['video_id'];
}
}
// get previous picture id
$result = $pdo->prepare('SELECT video_id FROM video WHERE video_id < :video_id ORDER BY video_id DESC LIMIT 1');
if($result){
$result->execute(array(':video_id' => $video_id));
//$result->execute(array(':video_cat_id' => $video_cat_id));
if (($row = $result->fetch()) !== FALSE) {
$prev_id = $row['video_id'];
}
}
$result = $pdo->prepare("SELECT * FROM video WHERE video_id= :video_id LIMIT 1");
if ($result->execute(array(':video_id'=>$_GET['video_id'])))
{
$prev_button = (isset($prev_id) && $prev_id>0)?'<a href="vcat-'.$video_cat_id.'/video-'.$prev_id.'.html"><i class="fa fa-arrow-left fa-3x"></i></a>':'';
$next_button = (isset($next_id) && $next_id>0)?'<a href="vcat-'.$video_cat_id.'/video-'.$next_id.'.html"><i class="fa fa-arrow-right fa-3x"></i></a>':'';
if($row = $result->fetch())
{
// video goes here
我在查询 SELECT * FROM video WHERE video_id= :video_id LIMIT 1
中看到的是我没有选择类别。
我尝试的是像这样进行查询
$result = $pdo->prepare("SELECT * FROM video WHERE video_id= :video_id and video_cat_id = :video_cat_id LIMIT 1");
$result->bindParam(':video_id', $_GET['video_id'], PDO::PARAM_INT);
$result->bindParam(':video_cat_id', $video_cat_id, PDO::PARAM_INT);
if ($result->execute())
{
// video
但是正在加载我的空白页面。这里的实际问题是什么?
更新:
这是我做的
// get next picture id
$result = $pdo->prepare('SELECT video_id FROM video WHERE video_id > :video_id and video_cat_id = :video_cat_id ORDER BY video_id ASC LIMIT 1');
if($result){
$result->bindParam(':video_id', $_GET['video_id'], PDO::PARAM_INT);
$result->bindParam(':video_cat_id', $video_cat_id, PDO::PARAM_INT);
$result->execute();
if (($row = $result->fetch()) !== FALSE) {
$next_id = $row['video_id'];
}
}
与上一张图片相同 - 在查询中添加了 video_cat_id。然后这个:
$prev_button = '<a href="vcat-'.$video_cat_id.'/video-'.$prev_id.'.html"><i class="fa fa-arrow-left fa-3x"></i></a>':'';
$next_button = '<a href="vcat-'.$video_cat_id.'/video-'.$next_id.'.html"><i class="fa fa-arrow-right fa-3x"></i></a>':'';
if(isset($prev_id) && $prev_id > 0) { echo $prev_button; }
if(isset($next_id) && $next_id > 0) { echo $next_button; }
if($row = $result->fetch())
{
我遇到错误:
PHP Parse error: syntax error, unexpected ':'
最佳答案
您的“第一个”和“上一个”SQL 查询应包含和 video_cat_id = :video_cat_id
,这样您就无法返回或前进到另一个类别。
那么,这段代码不是一个“if”语句...
$prev_button = (isset($prev_id) && $prev_id>0)?'<a href="vcat-'.$video_cat_id.'/video-'.$prev_id.'.html"><i class="fa fa-arrow-left fa-3x"></i></a>':'';
$next_button = (isset($next_id) && $next_id>0)?'<a href="vcat-'.$video_cat_id.'/video-'.$next_id.'.html"><i class="fa fa-arrow-right fa-3x"></i></a>':'';
if($row = $result->fetch())
{
// video goes here
定义按钮的外观及其应使用的参数。像这样...
$prev_button = '<a href="vcat-'.$video_cat_id.'/video-'.$prev_id.'.php"><i class="fa fa-arrow-left fa-3x"></i></a>':'';
$next_button = '<a href="vcat-'.$video_cat_id.'/video-'.$next_id.'.php"><i class="fa fa-arrow-right fa-3x"></i></a>':'';
然后使用 if 语句来决定是否应该显示它们。基本上...
如果该类别中有以前的视频 - 显示按钮。
如果该类别中有下一个视频 - 显示按钮。
if(isset($prev_id) && $prev_id > 0) { echo $prev_button; }
if(isset($next_id) && $next_id > 0) { echo $next_button; }
if($row = $result->fetch())
{
// video goes here
更新:
我完全错过了这个...您的按钮正在重定向到 .html
页面。 .html
或.htm
页面无法处理php
。您需要将页面更改为 .php
并将 $prev_button =
和 $next_button =
的代码更改为指向 .php
页面,就像我上面所做的那样。
关于php - 按钮上一个和下一个从 "end"或 "first"值之后的数据库元素加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32437187/
根本不是 SQL 人员。让顾问编写以下代码。 首先,它确保只选择了一所小学 - 然后,在 BEGIN 之后,如果变量 @Term 等于 3,我们想要在 IF 语句下执行操作。问题就在这里。当 @Ter
以下 javascript 将 bool 值呈现到每个语句的右侧: var reg = new RegExp(/^[\w\/].*result\b/); console.log(reg.test('p
有什么区别: x = 1 while x < 5 do x += 1 print x end 和: x = 1 while x < 5 x += 1 print x end 将 do
对于初学者来说,我是编程的“菜鸟”,所以只需了解事情的工作原理并向社区寻求帮助。 但是...我想知道的是: 我想要构建一个 Web 应用程序,两个主要用户界面之一实际上是日历产品。每个日历项目都有 8
我正在尝试制作带有图片上传选项的表单。我正在使用 express-http-proxy作为我的 API 代理和 multer按照建议。 app.use('/api', upload.any(), pr
根据this中的回答和 this问题,C++ 标准在 § 23.2.1 中声明 end() 对于所有 STL 容器都具有恒定的时间复杂度。 如果我理解正确的话: std::forward_list 只
当我使用 css 属性 align-items 时,我看不到 flex-end 值或 end 值有任何视觉差异>. align-items: end 和 align-items: flex-end 有
Sub RowRangeMove() Sheets.Add().Name = "CopySheet" With Sheets("BigDataSet - Copy")
假设第 1 到 5,000 列中有 25,000 到 50,000 行数据,每列可能有不同的行数。所有数据都是连续的,即列中没有空行,也没有空列。 考虑以下代码 Dim i As Long Dim W
我在 MYSQL 中有一个表,必须在 postgresql 中转换它。 我正在使用以下命令创建表格。 create table emp(COMPLETE BOOLEAN NOT NULL, END B
我正在尝试使用 Lark 为 BASIC 创建一个 LALR 解析器,而且我很难解决“END”语句和“END IF”等语句之间的冲突。这是语法的简化版本: %ignore /[ \t\f]+/ pro
试图理解this MSDN sample但我对这些行感到困惑: IAsyncResult result = Dns.BeginGetHostEntry(args[0], null, null); Co
我在 http://www.sgi.com/tech/stl/nth_element.html 阅读了 std::nth_element 的描述 template void nth_element(
为什么标准将 end() 定义为末尾,而不是实际末尾? 最佳答案 最好的论据是Dijkstra himself 提出的论据。 : 您希望范围的大小是一个简单的差异end - begin; 当序列退化为
我试图根据一些参数停止页面的其余部分加载;但不确定语法是否正确。 @if(dayRes + dayTri == 2){Sorry, etc @Response.End} 上面抛出这个错误: CS150
在二分搜索中,我们通常有 low 和 high 变量,并且通常有一个 while 循环来测试 low <= high,如以下代码所示(来自维基百科): int SortedArray[max] = {
我将 MS-Test 与 Visual Studio 2010 和 Visual Basic 结合使用。 在下面的函数中,代码覆盖率告诉我,有一个未检查的 block ,并且带有 “End Try”
所以今天我一直致力于使用 Protractor 为 Angular JS 应用程序设置端到端测试。为了编写更清晰的测试,我使用了 Protractor 网站上描述的 Page Object 模式。 测
所以 meteor js 的全部意义在于允许用户一次对整个堆栈进行编码,但是如果我正在使用像 django 这样的旧框架之一,可以借用meteor js的前端代码吗?比如前端的数据库同步,模板化,或者
我正在使用 wavesurfer.js 和 recorder.js 制作采样器。一切都很顺利,除了我无法使用 play([start[, end]]) 调整循环长度。 wavesurfer.seekT
我是一名优秀的程序员,十分优秀!