I want to add this line
a href="r.php?id=<?php echo $row['id']; ?>" >Details>
which will display details of this id on another page.
but i don't know how to write this line correctly. can you help me please thank you.
$conn = new mysqli('localhost', 'root', '', 'dbmtc');
$perPage = 10;
$page = 0;
if (isset($_POST['page'])) {
$page = $_POST['page'];
} else {
$page=1;
};
$startFrom = ($page-1) * $perPage;
$sqlQuery = "SELECT fname, lname, dept, email
FROM staff ORDER BY fname ASC LIMIT $startFrom, $perPage";
//echo $sqlQuery;
$result = mysqli_query($conn, $sqlQuery);
$paginationHtml = '';
while ($row = mysqli_fetch_assoc($result)) {
$paginationHtml.='<tr>';
$paginationHtml.='<td>'.$row["fname"].' '.$row["lname"].'</td>';
$paginationHtml.='<td>'.$row["dept"].'</td>';
$paginationHtml.='<td>'.$row["email"].'</td>';
**this line should be here**
$paginationHtml.='</tr>';
}
$jsonData = array(
"html" => $paginationHtml,
);
echo json_encode($jsonData);
?>
This part is in index.php
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Department</th>
<th>Email</th>
<th>Operations</th>
</tr>
</thead>
<tbody id="content">
</tbody>
</table>
And when i insert
$paginationHtml .= '<td><a href="r.php?id=' . $row['id'] . '">Details</a></td>';
I got this I don't why, that why I said it's not good
enter image description here
My Answer:
It looks like you are trying to add a link to another page in your table for each row of data. The issue you are facing might be due to the fact that you are trying to access the 'id' field from the $row variable, but you have not selected the 'id' field in your SQL query.
To fix this issue, you need to modify your SQL query to select the 'id' field along with other fields. Here is how you can update your SQL query:
php
$sqlQuery = "SELECT id, fname, lname, dept, email
FROM staff ORDER BY fname ASC LIMIT $startFrom, $perPage";
Now, you can access the 'id' field in your $row variable and add the link to another page like this:
php
$paginationHtml .= 'Details ';
Make sure that the 'id' field is present in your database table and is being selected in your SQL query. This should resolve the issue you are facing with adding the link to another page.
Rate this post
5 of 5 based on 9758 votesComments