2011-01-12 28 views
0

我想創建一個表,顯示一個MySQL表的值。問題是,當我打開頁面時,我只有列名。但我沒有看到任何行。我也想製作每一行的超鏈接。我將如何做到這一點。PHP表問題

這裏是我的代碼:

<?php 
    include_once 'rnheader.php'; 
    echo '</br>'; 

    echo '<a href = "rnservices.php"> Create Service</a> '; 

    echo '<table>'; 
    echo '<tr>'; 
    echo '<th>Service ID</th>'; 
    echo '<th>Title</th>'; 
    echo '<th>Description</th>'; 
    echo '<th>Notes</th>'; 
    echo '<th>Submit By</th>'; 
    echo '<th>Assigned Employee</th>'; 
    echo '<th>Assigned Group</th>'; 
    echo '<th>Category</th>'; 
    echo '<th>Status</th>'; 
    echo '<th>Urgency</th>'; 
    echo '<th>Customer</th>'; 
    echo '<th>Day Created</th>'; 
    echo '</tr>'; 

    $query = ("SELECT ServiceID, Title, Description, Notes, " 
      ."     SubmitBy, AssignedEmp, AssignedGroup, " 
      ."     NameCategory, TipoStatus, TiposUrgencia, " 
      ."     CustomerName, DayCreation " 
      ."FROM Service"); 

    $result = queryMysql($query); 
    echo 'Number of Rows: ' . mysql_num_rows($result); 

    while ($row = mysqli_fetch_assoc($result)) { 
    echo '<tr>'; 
    echo '<td>' . $row['ServiceID'] . '</td>'; 
    echo '<td>' . $row['Title'] . '</td>'; 
    echo '<td>' . $row['Description'] . '</td>'; 
    echo '<td>' . $row['Notes'] . '</td>'; 
    echo '<td>' . $row['SubmitBy'] . '</td>'; 
    echo '<td>' . $row['AssignedEmp'] . '</td>'; 
    echo '<td>' . $row['AssignedGroup'] . '</td>'; 
    echo '<td>' . $row['NameCategory'] . '</td>'; 
    echo '<td>' . $row['TipoStatus'] . '</td>'; 
    echo '<td>' . $row['TiposUrgencia'] . '</td>'; 
    echo '<td>' . $row['CustomerName'] . '</td>'; 
    echo '<td>' . $row['DayCreation'] . '</td>'; 
    echo '</tr>'; 
    } 

    mysqli_free_result($result); 
    echo '</table>'; 
?> 
+0

mysql_error()顯示什麼? – Tobias 2011-01-12 14:50:29

+0

mysqli_fetch_assoc是我的錯。但是可以創建每行的超鏈接? – maltad 2011-01-12 14:50:56

+2

您沒有關閉表格......您應該首先查看生成的HTML代碼。 – 2011-01-12 14:52:03

回答

0

試試這個:

//not tested 
<p> 
include_once 'rnheader.php'; 
</p> 
<p> 
echo '<a href = "rnservices.php"> Create Service</a> '; 
</p> 

echo '<table>'; 
echo '<tr>'; 
echo '<th>Service ID</th>'; 
echo '<th>Title</th>'; 
echo '<th>Description</th>'; 
echo '<th>Notes</th>'; 
echo '<th>Submit By</th>'; 
echo '<th>Assigned Employee</th>'; 
echo '<th>Assigned Group</th>'; 
echo '<th>Category</th>'; 
echo '<th>Status</th>'; 
echo '<th>Urgency</th>'; 
echo '<th>Customer</th>'; 
echo '<th>Day Created</th>'; 
echo '</tr>'; 


$query = ("SELECT ServiceID, Title, Description, Notes, SubmitBy, AssignedEmp, " . 
"AssignedGroup, NameCategory, TipoStatus, TiposUrgencia, CustomerName, DayCreation FROM Service"); 

// Perform Query 
$result = mysql_query($query); 

//use results 
while ($row = mysql_fetch_assoc($result)) { 
    echo '<tr>'; 
    echo '<td>'.$row['ServiceID'].'</td>'; 
    echo '<td>'.$row['Title'].'</td>'; 
    echo '<td>'.$row['Description'].'</td>'; 
    echo '<td>'.$row['Notes'].'</td>'; 
    echo '<td>'.$row['SubmitBy'].'</td>'; 
    echo '<td>'.$row['AssignedEmp'].'</td>'; 
    echo '<td>'.$row['AssignedGroup'].'</td>'; 
    echo '<td>'.$row['NameCategory'].'</td>'; 
    echo '<td>'.$row['TipoStatus'].'</td>'; 
    echo '<td>'.$row['TiposUrgencia'].'</td>'; 
    echo '<td>'.$row['CustomerName'].'</td>'; 
    echo '<td>'.$row['DayCreation'].'</td>'; 
    echo '</tr>'; 
} 
echo '</table>'; 
0

爲了使該行的領域進入一個鏈接,你可以做這樣的事情:

echo '<td><a href="whateverpage?id='.$row['ServiceId'].'">'. $row['Title'] . '</a></td>';