2014-09-10 47 views
0

好的,所以我在下面的頁面中,它從數據庫中拉回了一些細節。最後一行顯示了我在特定狀態下有多少行。在PHP文件中顯示MySQL的DIV的位置

我的問題我想在頁面頂部而不是底部顯示此內容,如果我將最後一行復制到頂部,它不會正確計數,只顯示1而不是2,因爲它顯示在底部。任何想法如何能包括這個最後的div在頂部,但它顯示正確的輸出?

任何幫助將是非常有用的。

<h2>All P1 Issues</h2> 
<table class="table table-striped table-bordered table-head-bordered-bottom table-condensed"> 
    <thead> 
    <tr> 
     <th class=span1>Ticket ID</th> 
    <th class=span2>Title</th> 
    <th class=span2>Submitter</th> 
    <th class=span2>Owner</th> 
    <th class=span2>Status</th> 
    <th class=span1>Created</th> 
    <th class=span1>Modified</th> 
    </tr> 
</thead> 
<tbody> 

<?php 

$query1 = " 
SELECT HD_TICKET.ID as ID, 
HD_TICKET.TITLE as Title, 
HD_STATUS.NAME AS Status, 
HD_PRIORITY.NAME AS Priority, 
HD_TICKET.CREATED as Created, 
HD_TICKET.MODIFIED as Modified, 
S.FULL_NAME as Submitter, 
O.FULL_NAME as Owner, 
HD_TICKET.CUSTOM_FIELD_VALUE0 as Type 
FROM HD_TICKET 
JOIN HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID) 
JOIN HD_PRIORITY ON (HD_PRIORITY.ID = HD_TICKET.HD_PRIORITY_ID) 
LEFT JOIN USER S ON (S.ID = HD_TICKET.SUBMITTER_ID) 
LEFT JOIN USER O ON (O.ID = HD_TICKET.OWNER_ID) 
WHERE HD_TICKET.HD_QUEUE_ID IN(1,3) AND 
(HD_PRIORITY.NAME like '%High%') OR 
(HD_STATUS.NAME like '%Critical%') 
ORDER BY Owner, Created DESC 
"; 


$result1 = mysql_query($query1); 
$num = mysql_numrows($result1); 
$i = 0; 
    while ($i < $num) 
{ 
$ID = mysql_result($result1,$i,"ID"); 
$Title = mysql_result($result1,$i,"Title"); 
$Status = mysql_result($result1,$i,"Status");   
$Type = mysql_result($result1,$i,"Type"); 
$Created = mysql_result($result1,$i,"Created"); 
$Modified = mysql_result($result1,$i,"Modified"); 
$Priority = mysql_result($result1,$i,"Priority"); 
$Owner = mysql_result($result1,$i,"Owner"); 
$Submitter = mysql_result($result1,$i,"Submitter"); 


$ID = stripslashes($ID); 
$Title = stripslashes($Title); 
$Status = stripslashes($Status); 
$Type = stripslashes($Type); 
$Created = stripslashes($Created); 
$Modified = stripslashes($Modified); 
$Priority = stripslashes($Priority); 
$Owner = stripslashes($Owner); 
$Submitter = stripslashes($Submitter); 



$StatusSpan=""; 
if ($Status=="Stalled") 
{ 
    $StatusSpan="<span class='label label-warning'>$Status</span>"; 
} 

$PriortySpan=""; 
if ($Priority=="High") 
{ 
    $PriortySpan="<span class='label label-important'><i class='icon-exclamation-sign icon-white'></i>High</span>"; 
} 

if ($Priority=="Low") 
{ 
    $PriortySpan="<span class='label'>Low</span>"; 
} 

if ($Priority=="Medium") 
{ 
    $PriortySpan="<span class='label'>Medium</span>"; 
} 

if ($Priority=="Critical") 
{ 
    $PriortySpan="<span class='label'><i class='icon-exclamation-sign icon-white'></i>Critical</span>"; 
} 



echo "<tr><td><a href='http://$KaceBoxDNS/adminui/ticket.php?ID=$ID' target='_blank'>$ID</a>  $StatusSpan $PriortySpan</td> \n"; 
echo "<td>$Title</td> \n"; 
echo "<td>$Submitter</td> \n"; 
echo "<td>$Owner</td> \n"; 
echo "<td>$Status</td> \n"; 
echo "<td>$Created</td> \n"; 
echo "<td>$Modified</td> \n"; 
echo "</tr> \n"; 
$i++; 
} 

echo "<p><span class='label label-important'>$num P1 Issues</span></p>"; 
echo "</tbody></table> \n"; 
?> 
<center><div class="alert alert-success" role="alert"><strong>No Current</strong><?php echo "<p><span class='label label-important'>$num P1 Issues</span></p>"; ?> Critical/High Priority Incidents</div></center> 
+0

做你把處理代碼「最後的div」上述 – 2014-09-10 12:51:40

+1

嘗試之前所有的HTML標記移動整個''。 – 2014-09-10 12:52:10

+1

Alo停止使用mysql_ *函數已被棄用。開始使用mysqli_ *和PDO代替.. – Naruto 2014-09-10 12:53:01

回答

0

可以在&跳了PHP的一個HTML代碼。

下面是一個例子。 同樣在HTML中,您可以使用<br><br />作爲/n用於文本中斷行。最後一點:mysql*已被棄用,我建議使用PDO,因爲這很有趣。

<?php 

$query1 = " 
SELECT HD_TICKET.ID as ID, 
HD_TICKET.TITLE as Title, 
HD_STATUS.NAME AS Status, 
HD_PRIORITY.NAME AS Priority, 
HD_TICKET.CREATED as Created, 
HD_TICKET.MODIFIED as Modified, 
S.FULL_NAME as Submitter, 
O.FULL_NAME as Owner, 
HD_TICKET.CUSTOM_FIELD_VALUE0 as Type 
FROM HD_TICKET 
JOIN HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID) 
JOIN HD_PRIORITY ON (HD_PRIORITY.ID = HD_TICKET.HD_PRIORITY_ID) 
LEFT JOIN USER S ON (S.ID = HD_TICKET.SUBMITTER_ID) 
LEFT JOIN USER O ON (O.ID = HD_TICKET.OWNER_ID) 
WHERE HD_TICKET.HD_QUEUE_ID IN(1,3) AND 
(HD_PRIORITY.NAME like '%High%') OR 
(HD_STATUS.NAME like '%Critical%') 
ORDER BY Owner, Created DESC 
"; 


$result1 = mysql_query($query1); 
$num = mysql_numrows($result1); 
$i = 0; 
    while ($i < $num) 
{ 
$ID = mysql_result($result1,$i,"ID"); 
$Title = mysql_result($result1,$i,"Title"); 
$Status = mysql_result($result1,$i,"Status");   
$Type = mysql_result($result1,$i,"Type"); 
$Created = mysql_result($result1,$i,"Created"); 
$Modified = mysql_result($result1,$i,"Modified"); 
$Priority = mysql_result($result1,$i,"Priority"); 
$Owner = mysql_result($result1,$i,"Owner"); 
$Submitter = mysql_result($result1,$i,"Submitter"); 


$ID = stripslashes($ID); 
$Title = stripslashes($Title); 
$Status = stripslashes($Status); 
$Type = stripslashes($Type); 
$Created = stripslashes($Created); 
$Modified = stripslashes($Modified); 
$Priority = stripslashes($Priority); 
$Owner = stripslashes($Owner); 
$Submitter = stripslashes($Submitter); 



$StatusSpan=""; 
if ($Status=="Stalled") 
{ 
    $StatusSpan="<span class='label label-warning'>$Status</span>"; 
} 

$PriortySpan=""; 
if ($Priority=="High") 
{ 
    $PriortySpan="<span class='label label-important'><i class='icon-exclamation-sign  icon-white'></i>High</span>"; 
} 

if ($Priority=="Low") 
{ 
    $PriortySpan="<span class='label'>Low</span>"; 
} 

if ($Priority=="Medium") 
{ 
    $PriortySpan="<span class='label'>Medium</span>"; 
} 

if ($Priority=="Critical") 
{ 
    $PriortySpan="<span class='label'><i class='icon-exclamation-sign icon-white'>  </i>Critical</span>"; 
} 

?> 
<h2>All P1 Issues</h2> 
<table class="table table-striped table-bordered table-head-bordered-bottom table-condensed"> 
    <thead> 
    <tr> 
     <th class=span1>Ticket ID</th> 
    <th class=span2>Title</th> 
    <th class=span2>Submitter</th> 
    <th class=span2>Owner</th> 
    <th class=span2>Status</th> 
    <th class=span1>Created</th> 
    <th class=span1>Modified</th> 
    </tr> 
</thead> 
<?php 

/* THIS IS THE IMPORTANT PART FOR YOUR STUFF */ 

echo "<tr><td><a href='http://$KaceBoxDNS/adminui/ticket.php?ID=$ID' target='_blank'>$ID</a>  $StatusSpan $PriortySpan</td> \n"; 
echo "<td>$Title</td><br>"; 
echo "<td>$Submitter</td><br>"; 
echo "<td>$Owner</td><br>"; 
echo "<td>$Status</td><br>"; 
echo "<td>$Created</td><br>"; 
echo "<td>$Modified</td><br>"; 
echo "</tr> \n"; 
$i++; 
} 

?> 

<tbody> 
<?php 

echo "<p><span class='label label-important'>$num P1 Issues</span></p>"; 
echo "</tbody></table><br>"; 

?> 

<center><div class="alert alert-success" role="alert"><strong>No Current</strong><?php echo "<p><span class='label label-important'>$num P1 Issues</span></p>"; ?> Critical/High Priority Incidents</div></center> 
+0

只是一個側面說明,如果在查詢中有結果,反正只會顯示DIV嗎? – user3653189 2014-09-10 19:11:07

+0

like:''''<?php if($ result1){?>

'''' – 2014-09-10 19:20:18