当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - PHP table problem

问题描述:

Im want to create a table that show the values of a mysql table. The problem is that when I open the page I only have the columns name. But I dont see any row. I also want to make a hyperlink of each row. How I will do that.

Here is my code:

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

?>

网友答案:

Try this:

//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>';
网友答案:

Maybe following along with this datagrid tutorial will be helpful?

网友答案:

To make a field of the row into a link, you can do something like this:

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

网友答案:

Try this sort of thing for the hyperlinks.

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: