i have text file created , appended user , using format append it. new line after every input , separated semicolon:
movie title1; movie rating1; plot1;
movie title2; movie rating2; plot2;
movie title3; movie rating3; plot3;
etc. etc.
i have managed fix above , want read specific line text file echo it. specific line found through $get parameter , based on movie title.
for example click on link, in case title movie, title name through $get: movies.php change movies.php?title=movietitle. , current movie title name , read specific line , echo it. here code:
//writes input user 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."\n"); fclose($handle); } ?> //reads line movies.txt , adds li, movie title becoming link <?php $filename = 'movies.txt'; $handle = fopen($filename, 'r'); $datain = fread($handle, filesize($filename)); $lines = explode ("\n",trim($datain)); foreach($lines $line) { list($title,$rating,$plot) = explode(";",$line,3); echo '<li><a href="movies.php?title='.$title.'">'.$title.'</a><span>'.$rating.'</span></li>'; } ?>//so far //and want read title name, , based on //title name find specific line rating , plot //which belongs current clicked movie title... <?php if (isset($_get["title"])) { $readin = file('movies.txt'); foreach ($readin $fname) $names_array = explode(';', $fname); { echo '<h1>'.$names_array[0]./*movietitlename*/'</h1>''<h2>'.$rating.'</h2>'.$plot;//so want echo specific "movietitle movie, movierating , movieplot". i've done far wrong, need here! } } ?> so want echo out movie title being in , and movie rating .i hope understand question, in advance!
try code
if (isset($_get["title"])) { $readin = file('movies.txt'); foreach ($readin $fname) { $names_array = explode(';', $fname);//this has go here if($_get['title']==$names_array[0]){ echo '<h1>'.$names_array[0].'</h1><h2>'.$names_array[1].'</h2>'.$names_array[2]; } } }
Comments
Post a Comment