0

如果用户单击修改视频链接有条件,我试图让前面代码中查询的行在其中回显。但是,当我直接在 if ($videoEdit) { 条件上方回显 $video 变量时,它会显示在页面上,但是如果我尝试在 if ($videoEdit) { 条件下回显它,由于某种原因它不会输出。我很困惑。这是我的代码(不包括查询,但 echo $video 在有条件之前会输出正确的结果)

添加:::

require ('../mysql_connect.php'); // Connect to DB

    // Handle Video Edit
   if ($_GET['video'] == "EDIT") {

$videoEdit = TRUE;

   }

    $query = "SELECT inventory.inv_key, inventory.mdl_key, inventory.serial, inventory.date_aquired, inventory.location, inventory.price, model.mdl_key, model.man_key, model.cls_key, model.sub_cls_key, model.model, model.video, model.picture, model.pdf, subclass.sub_cls_key, subclass.subclass, class.cls_key, class.class, manufacturer.man_key, manufacturer.manufacturer FROM inventory, manufacturer, model, class, subclass WHERE inventory.mdl_key='$_GET[mdl_key]' AND model.mdl_key='$_GET[mdl_key]' AND class.cls_key='$_GET[cls_key]' AND subclass.sub_cls_key='$_GET[sub_cls_key]' AND manufacturer.man_key='$_GET[man_key]' AND manufacturer=manufacturer.manufacturer AND class=class.class AND subclass=subclass.subclass";
$result = @mysql_query ($query); // Run the query

while ($row = mysql_fetch_array 
($result, MYSQL_ASSOC)) {
$model = $row['model'];
$mdl_key = $row['mdl_key'];
$video = $row['video'];
$picture = $row['picture'];
$pdf = $row['pdf'];
$description = $row['description'];
$manufacturer = $row['manufacturer'];
$man_key = $row['man_key'];
}

上面的补充::::

if ($_GET['video'] == 'EDIT') { 
$videoEdit = TRUE; 
}

while ($row = mysql_fetch_array($result)) {
$video = $row['video'];
}

if ($videoEdit) { // <-- boolean comparison
echo '<form action="edit_media.php" method="post">
<p>Video Link: <input type="text" name="serial" size="25" maxlength="100" value=';
       if (isset($video))
            echo $video;
        }
            echo ' /></p><p><input type="submit" name="submit" value="Submit Video" /></p>               <input type="hidden" name="submitted" value="TRUE" />
        </form>';
}

加法::这是,在我的代码中,直接在上面的代码下面

if ($video != "") {
    echo '<iframe width="420" height="315" src=' . $video . ' frameborder="0" allowfullscreen></iframe> | <a href=edit_media.php?video=EDIT&mdl_key=' . $mdl_key . '&man_key=' . $man_key . '>Modify Video Link</a>';
} else {
    echo "Video Not Present | <a href=edit_media.php?video=EDIT>Add a Video</a>";
}
4

3 回答 3

1

您在 html 字符串 ' /></p>...' 的其余部分之前缺少回显

if (isset($video))
      echo $video;

echo ' /></p><p><input type="submit" name="submit" value="Submit Video" /></p> <input type="hidden" name="submitted" value="TRUE" /></form>';
于 2012-10-30T14:44:17.200 回答
0

最有可能的$video是,未设置。

您应该尝试echo $video;while循环之后。此外,除非您只获取单个结果,否则不应使用循环。

$row = mysql_fetch_array($result);
$video = $row['video'];
echo $video;

更新

以下是我将如何解决您的问题(显然替换mysql_函数):

if ($_GET['video'] == 'EDIT') { 
    $result = mysql_query("SELECT ... ");
    $row = mysql_fetch_array($result);
    $video = $row['video'];

    echo '<form action="edit_media.php" method="post">
    <p>Video Link: <input type="text" name="serial" size="25" maxlength="100" value='";
    if (isset($video)) {
        echo $video;
    }

    echo '" /></p><p><input type="submit" name="submit" value="Submit Video" /></p>               <input type="hidden" name="submitted" value="TRUE" />
            </form>';
    }

}

还注意到您缺少打开的大括号 ( ),以及HTML 中{的值周围的双引号。$video

于 2012-10-30T14:48:14.880 回答
0

不确定这是否是答案,但在尝试回显 $video 内容之后,您似乎需要另一个“回声”才能继续循环。在这之前:

' /></p><p><input type="submit" name="submit" value="Submit Video" /></p>               <input type="hidden" name="submitted" value="TRUE" />
于 2012-10-30T14:45:01.920 回答