PHP表问题

时间:2011-01-12 14:46:09

标签: php mysql

我想创建一个显示mysql表值的表。问题是,当我打开页面时,我只有列名。但我没有看到任何排。我还想制作每一行的超链接。我将如何做到这一点。

这是我的代码:

<?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>';
?>

4 个答案:

答案 0 :(得分:0)

也许关注此datagrid tutorial会有所帮助吗?

答案 1 :(得分: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>';

答案 2 :(得分:0)

要将行的字段设置为链接,您可以执行以下操作:

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

答案 3 :(得分:0)

尝试这种超链接。

http://www.jsfiddle.net/dduncan/FQwKR/1/