I have a basic website that pulls the data from a .csv file and displays only the first column, I am having trouble in creating a way that will let you select one of those values in the first column, to then open a new table of only that entire row's contents.
the table displayed looks like this:
| Title |
|---|
| Book1 |
| Book2 |
| .... |
| Book n |
maybe a dropdown or something that will let you select Book1 and when you click a button will open a new html/php page with the remaining column entries for the Book1 row, as such that table looks like:
| Title | Author | Year |
|---|---|---|
| Book1 | Author1 | 2020 |
Here is the code for the Book Displaying table:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./css/styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Submission</title></
</head>
<body style="font-family:Verdana;color:#aaaaaa;">
<div style="background-color:#e5e5e5;padding:15px;text-align:center;">
<h1>View Publications</h1>
</div>
<div style="overflow:auto">
<div class="menu">
<a href="./index.php">HOME</a>
<a href="./CV.php">CV</a>
<a href="./forecast.php">Weather</a>
<?php session_start();
if(!isset($_SESSION['loggedin']))echo "<a href='./session.php'>Log in</a>";
else {echo "<a href='./session.php'>Admin Panel</a>";}
?>
</div>
<div class="main">
<h2>All Publications on File</h2>
<?php
$row = 1;
if (($handle = fopen("publications.csv", "r")) !== FALSE) {
echo '<table border="1">';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if ($row == 1) {
echo '<thead><tr>';
}else{
echo '<tr>';
}
$c=0;
if(empty($data[$c])) {
$value = " ";
}else{
$value = $data[$c];
}
if ($row == 1) {
echo '<th>'.$value.'</th>';
}else{
echo '<td>'.$value.'</td>';
}
if ($row == 1) {
echo '</tr></thead><tbody>';
}else{
echo '</tr>';
}
$row++;
}
echo '</tbody></table>';
fclose($handle);
}
?>
</div>
<div class="right">
<h2>Users </h2>
<?php if(isset($_SESSION['loggedin']))echo "<p> You Are Logged in as an admin</p>";
else {echo "<p> No Admins Logged in!!</p>";}
?>
</div>
</div>
<div style="background-color:#e5e5e5;text-align:center;padding:10px;margin-top:7px;">#STUDENT NUMBER</div>
</body>
</html>
I understand that by modifiying the $c in the <php> tag, into a for loop will traverse each column to display a full table, my issue is filtering where row = book chosen by user
row$variable as the index to pass to the next page, and repeat your same process to "find" that row. If possible, I'd also encourage you to look into a database.fgetcsvgets you each row.