按钮不';t出现在while循环之后,即使我把它放在循环之前它也有效


Button doesn't appear after while cycle even though it works if i put it before cycle

我有一个带有管理按钮的footer.php,当我把它放在页面末尾时,按钮不会出现。。但如果我把它放在这个代码之前:

<?php if ($row["rights"]=="2"):?>
<div id='cssmenu-admin'>
<ul>
<li name='admin' class='active'><a href='administration.php'><span>Admin</span></a></li>
</ul>
</div>
<?php endif; ?>

在while cycle之前从footer.php开始,它的工作方式与应该的一样。

这是我的footer.php文件:

<div id="footer">
<hr>Copyrighted (C) 2014 by djdanas@gmail.com<br>
<?php if ($row["rights"]=="2"):?>
<div id='cssmenu-admin'>
<ul>
<li name='admin' class='active'><a href='administration.php'><span>Admin</span></a></li>
</ul>
</div>
<?php endif; ?>
</div>
<br><hr>

这是我的页面文件:

<!DOCTYPE HTML> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Pagrindinis</title>
<link href="CSS/stilius.css" rel="stylesheet" type="text/css"/>
<link href="CSS/menu.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<?php require("includes/validate.php");?>
<?php require("includes/stilius.php");?>
<?php
require("includes/connection_to_db.php");
$sql = "SELECT prekės.* , CONCAT(vartotojai.name) as v_name
    FROM prekės 
    LEFT JOIN vartotojai
    ON vartotojai.V_ID=prekės.V_ID
    ORDER BY prekės.date 
    DESC LIMIT 8";
    $result = mysql_query("$sql");
?>
<?php mysql_close(); ?>
<?php while ($row = mysql_fetch_assoc($result)) : ?>
    <?php $image = '<td><img src="data:image/jpeg;base64,'.base64_encode($row['image']).'" name="pix" width="270" height="200"/></td>' ?>
    <table class="two">
    <th><?php echo $row['name'] ?></th>
    <th>Prekės savininkas: <?php echo $row['v_name']?></th>
            <th><input type="button" value="Mainyti"></th>
            <tr>
            <?php echo $image?>
            <td><textarea disabled style="resize:none; background-color:white" name="about" rows="12" cols="65"><?php echo $row['specs']?></textarea><td>   
    </table>
<?php endwhile; ?>  
<?php require("includes/footer.php");?>
</body>
</html>

编辑:

好的,我通过添加新的变量解决了我的问题

$rights = $row['rights'];

之后

<!DOCTYPE HTML> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Pagrindinis</title>
<link href="CSS/stilius.css" rel="stylesheet" type="text/css"/>
<link href="CSS/menu.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<?php require("includes/validate.php");?>
<?php require("includes/stilius.php");?>

在我的页面文件中,并从更改了我的footer.php文件中的1行

<?php if ($row['rights']=="2"):?>

<?php if ($rights="2"):?>

现在它像一个符咒一样工作:)

我在黑暗中捅一刀,说你的测试

if ($row["rights"]=="2")

意味着您正在检查登录的用户是否具有2的"权限"?

然后当你循环查询时。。。

while ($row = mysql_fetch_assoc($result))

您正在覆盖$row变量。所以,无论你一开始认为是什么,现在都不是了。您应该为用户或循环查询使用不同的变量。

编辑:一旦你到达测试位置,变量也可能不在范围内。你可以尝试在footer.php中使用print_r($row)来查看$row中当前的内容,这应该会有所帮助。