我在一个可以为视频添加标签的网站上工作。此屏幕截图应该概述结果应如何:
http://www.unistamp.ch/images/images.html
嵌入带注释的视频,右边有一个Iframe,其中从MYSQL数据库访问时间轴上注释的详细信息。 这是video_comment表的截图。
我想根据他的评论ID从数据库中删除特定评论。 我尝试了这段代码但是通过点击X按钮传递纪念品是行不通的:
<?php
include '../../../DB/MySql/connectVideoPhase.php';
//****** Delete Row in table
if(isset($_POST['X']))
{
$comment_id = $_POST['comment_id'];
//CHeck --> doesnt work
echo "<pre> commentid= ".$comment_id . "</pre> ";
$sql = "DELETE video_converted_comment ".
"WHERE commentid = \"".$comment_id."\" ;";
$retval = mysql_query( $sql);
if(! $retval )
{
die('Could not delete data: ' . mysql_error()); }
echo "Deleted data successfully\n";
}
//**************************************
//******* Get the comments
$video_id = $_REQUEST['VideoId'];
// for testing use a specific video ID
if (! $video_id) {
$video_id = '153fb143';
}
$sqlSelectComment = "Select * from video_converted_comment WHERE videoid ='".$video_id."'";
$sqlComments = mysql_query($sqlSelectComment);
$i = mysql_num_rows($sqlSelectComment);
// *************************
//********* Fill Table
echo "
<table width=\"100\" border=\"1\" >
<tr>
<td width=\"25\"><b>start</b></td>
<td width=\"25\"><b>end</b></td>
<td width=\"75\"><b>Text</b></td>
<td width=\"5\"><b>X</b></td>
<td width=\"0\"><input type=\"hidden\"></td>
</tr>";
while ($comments = mysql_fetch_array($sqlComments))
{
echo "<tr><td>" .$comments['starttime'] ."</td>";
echo "<td>" .$comments['endtime'] ."</td>";
echo "<td>" .$comments['text'] ."</td>";
echo "<td> <form method=\"post\" action=\"".$_PHP_SELF ."\">
<input name=\"comment_id\" type=\"hidden\" value=\"".$comments['id']."\">
<button name=\"X\" type=\"submit\" value=\"".$comments['id']."\"> </td>
</form>";
}
echo "</table> ";
任何基于使用PHP的纪念品删除/添加评论到DB的任何帮助都将非常感激! 用javascript做它会更容易吗?视频下方的时间线可视化使用javascript完成。
答案 0 :(得分:1)
在玩了很长一段时间之后,代码正在运行。
在表格中点击delte按钮后,脚本会删除MySQL表格中的行。
错误1 是:整个表格显示在iframe中。当它被包含在网站上
<iframe id=\"commentTable\" src=\"DB/MySql/CommentTableAndDelete.php?VideoId=".$ID."..
Id在网址中传递,并由
访问 $video_id = $_REQUEST['VideoId'];
当脚本在删除条目后加载自身时,这不起作用,因为表单的方法是“post”。
这可能不是最好的方法,但它有效:
$video_id = $_REQUEST['VideoId'];
// if script loads itself
if (! $video_id) {
$video_id = $_POST['VideoId'];
}
错误2 是表格。不知何故,由于Typo,它没有通过变量 这有效:
<form method=\"post\" action=\"".$_PHP_SELF ."\">
<input id=\"comment_id\" name=\"comment_id\" type=\"hidden\" value=\"".$comments['commentid']."\">
<button name=\"X\" type=\"submit\" value=\"X\">
错误3 Sql语句不正确。我在将语句粘贴到php代码之前在phpmyadmin中测试了它。
$sql = "DELETE FROM video_converted_comment WHERE commentid='".$comment_id."' ;";
工作代码:
//******* Get the comments
$video_id = $_REQUEST['VideoId'];
if (! $video_id) {
$video_id = $_POST['VideoId'];
}
$sqlSelectComment = "Select * from video_converted_comment WHERE videoid ='".$video_id."';";
$sqlComments = mysql_query($sqlSelectComment);
if(! $sqlComments )
{ die('Could not get Comments from DB: ' . mysql_error()); }
$i = mysql_num_rows($sqlSelectComment);
// *************************
//****** Delete Row in table
//http://stackoverflow.com/questions/15843678/mssql-and-php-select-specific-row-based-on-which-button-is-clicked
if(isset($_POST['X']))
{
$comment_id = $_POST['comment_id'];
//CHeck
//echo "<pre> commentid= ".$comment_id . "</pre> ";
$sql = "DELETE FROM video_converted_comment WHERE commentid='".$comment_id."' ;";
$retval = mysql_query( $sql);
if(! $retval )
{ die('Could not delete data: ' . mysql_error()); }
echo "Deleted data successfully\n";
}
//**************************************
//********* Fill Table
echo "
<table width=\"100\" border=\"1\" >
<tr>
<td width=\"25\"><p>start</p></td>
<td width=\"25\"><p>end</p></td>
<td width=\"100\"><p>Text</p></td>
<td width=\"10\"><p>X</p></td>
</tr>";
while ($comments = mysql_fetch_array($sqlComments))
{
echo "<tr><td>" . gmdate("i:s", $comments['starttime']) ."</td>";
echo "<td>" . gmdate("i:s", $comments['endtime']) ."</td>";
echo "<td>" .$comments['text']."</td>";
echo "<td> <form method=\"post\" action=\"".$_PHP_SELF ."\">
<input id=\"comment_id\" name=\"comment_id\" type=\"hidden\" value=\"".$comments['commentid']."\">
<button name=\"X\" type=\"submit\" value=\"X\"> </td>
</form>";
}
echo "</table> ";
?>