I have a text file which is already created and appended by user and I am using this format to append it. New line after every input and separated by semicolon:
Movie Title1; Movie Rating1; Plot1;
Movie Title2; Movie Rating2; Plot2;
Movie Title3; Movie Rating3; Plot3;
Etc. etc.
I have managed to fix the above and now I want to read a specific line from the text file then echo it. This specific line is to be found through $GET parameter and based on Movie Title.
For example I click on a link, in this case a title from a movie, then I get the title name through $GET: movies.php to change to movies.php?title=MovieTitle. And then I get this current Movie Title name and read this specific line and echo it. Here is my code:
//Writes input from user to movies.txt
<?php
if (isset($_POST["submit"])) {
$title = $_POST['movieTitle'];
$rating = $_POST['movieRatings'];
$plot = $_POST['plot'];
$handle = fopen('movies.txt', 'a');
$names_array = array("$title","$rating","$plot");
$string = implode(';', $names_array);
fwrite($handle, $string."
");
fclose($handle);
}
?>
//Reads line from movies.txt and adds it to a li, with movie title becoming a link
<?php
$filename = 'movies.txt';
$handle = fopen($filename, 'r');
$datain = fread($handle, filesize($filename));
$lines = explode ("
",trim($datain));
foreach($lines as $line)
{
list($title,$rating,$plot) = explode(";",$line,3);
echo '<li><a href="movies.php?title='.$title.'">'.$title.'</a><span>'.$rating.'</span></li>';
}
?>//So far so good
//And now I want to read title name, and based on the
//title name find a specific line with rating and plot
//which belongs to current clicked movie title...
<?php
if (isset($_GET["title"])) {
$readin = file('movies.txt');
foreach ($readin as $fname)
$names_array = explode(';', $fname);
{
echo '<h1>'.$names_array[0]./*MovietitleName*/'</h1>''<h2>'.$rating.'</h2>'.$plot;//So I want to echo the specific "movieTitle movie, movieRating and moviePlot". What I've done so far is wrong, I need help here!
}
}
?>
So I want to echo it out with movie title being in and and movie rating .I hope you understand my question, thanks in advance!