好吧,我正在尝试创建支持票证系统,这应该从数据库检查Status是0还是0以上,如果它为零则应该说是Close Ticket,如果不是它应该说重新打开票证,但问题是它显示了两个按钮及其均匀的打印代码,我的意思是:
http://i.imgur.com/XMu9YSH.jpg
代码:
if($row > 0)
{
$other = "SELECT * FROM `Dashboard` WHERE `ID` = '$id'";
$result = mysqli_query($con, $other);
$output = mysqli_fetch_array($result);
$stanje = $row["Status"];
echo '
<br><div class="ticket_info">
if($stanje == 0 ) { <button class="lockticket" value="lockticketbutton">Close Ticket</button></a> }
else if($stanje != 0 ) { <button class="lockticket" value="lockticketbutton">Reopen Ticket</button></a> }
Postavio: '.$output['Postavio'].' --- ['.$output['Naslov'].']
</div>
</br><div class="ticket_info2">
'.$output['Text'].'
</div>
';
$odg = "SELECT * FROM `ticketcomments` WHERE `TicketID` = '$id'";
$result = mysqli_query($con,$odg);
while( $odgovor = mysqli_fetch_array($result,MYSQLI_ASSOC) )
{
echo '
<br><div class="ticket_odgovor">
Postavio: '.$odgovor['Poslao'].' --- [Odgovor na TiketID#'.$odgovor['TicketID'].']
</div>
</br><div class="ticket_odgovor2">
'.$odgovor['Odgovor'].'
</div>
';
}
答案 0 :(得分:2)
问题是您对字符串中的按钮进行条件检查,并将其传递给echo
语句。这不会被PHP视为条件,只是一个字符串。
您可以拥有多个echo语句而不会出现任何问题。尝试这样的事情:
echo '<br><div class="ticket_info">';
if($stanje == 0 ) {
echo ' <button class="lockticket" value="lockticketbutton">Close Ticket</button></a> ';
} else {
echo ' <button class="lockticket" value="lockticketbutton">Reopen Ticket</button></a>';
}
echo ...
答案 1 :(得分:1)
老兄,你有引号问题,试试这段代码:
if($row > 0){
$other = "SELECT * FROM `Dashboard` WHERE `ID` = '$id'";
$result = mysqli_query($con, $other);
$output = mysqli_fetch_array($result);
$stanje = $row["Status"];
echo '<br><div class="ticket_info">';
if($stanje == 0 ) {
echo '<button class="lockticket" value="lockticketbutton">Close Ticket</button></a>'; }
else if($stanje != 0 ) {
echo '<button class="lockticket" value="lockticketbutton">Reopen Ticket</button></a>'; }
echo 'Postavio: '.$output['Postavio'].' --- ['.$output['Naslov'].']</div></br><div class="ticket_info2">'.$output['Text'].'</div>';
$odg = "SELECT * FROM `ticketcomments` WHERE `TicketID` = '$id'";
$result = mysqli_query($con,$odg);
while( $odgovor = mysqli_fetch_array($result,MYSQLI_ASSOC) )
{
echo '
<br><div class="ticket_odgovor">
Postavio: '.$odgovor['Poslao'].' --- [Odgovor na TiketID#'.$odgovor['TicketID'].']
</div>
</br><div class="ticket_odgovor2">
'.$odgovor['Odgovor'].'
</div>
';
}