I'm totally new to this and am taking a class where the professor is absolutely not helpful. I'm trying to read data from a file into a table, but the data isn't showing up for some reason. I've tried it a few different ways, but I honestly am kind of lost. Any advice is much appreciated
Code is:
$filename = 'data/'.'booklist.txt';
$find_title = $_POST['title'];
$ascending = $_POST['ascending'];
$descending = $_POST['descending'];
list($total_rows, $theTable) = displayTable($filename);
if ($total_rows != 'No File')
{
print $theTable;
}
else
{
print "No file found";
}
function displayTable($filename)
{
$myTable = "\n<table border='1'>";
$myTable .= "<tr>";
$myTable .= " <th>Title</th>";
$myTable .= " <th>Type</th>";
$myTable .= " <th>Publication Date</th>";
$myTable .= " <th>ISBN</th>";
$myTable .= "</tr>\n\n";
$line_ctr = 0;
$fp = fopen($filename, 'r'); //opens the file for reading
if ($fp)
{
while(true)
{
$line = fgets($fp);
if (feof($fp))
{
break;
}
$line_ctr++;
$line_ctr_remainder = $line_ctr % 2;
if ($line_ctr_remainder == 0)
{
$style = "style='background-color: #FFFFCC;'";
} else {
$style = "style='background-color: white;'";
}
list($title, $type, $publicationdate, $isbn) = explode('*', $line);
$myTable .= "<tr $style>";
$mytable .= "<td>".$title."</td>";
$mytable .= "<td>".$type."</td>";
$mytable .= "<td>".$publicationdate."</td>";
$mytable .= "<td>".$isbn."</td>";
$mytable .= "</tr>\n";
}
fclose($fp );
$myTable .= "</table>";
$rtn = array($line_ctr, $myTable);
} else {
$rtn = array("No File", "dummy");
}
return $rtn;
print $mytable; //This prints the table rows
}
?>
</div>
</body>
</html>
Thank you!