xmanofsteel69 Posted February 4, 2007 Share Posted February 4, 2007 Hey everyone. I'm new to this site as I've got a big problem. I'm trying to create a website that displays a list of movies that I own (I know, stupid...but it's helping me learn PHP). But anyways, I have this file, and the bottom function, where it's suppose to display the 'Title' of the array...well...it's not displayed. I'm super lost and I'm not sure how to fix it. Any help would be amazing! <div style='display:none;'> <html> <head> <title>The Movie List</title> </head> <body> </div> <center> <form action="Movies.php" method="post"> <table border="0" bgcolor=black cellspacing="5"> <tr><td><font color=red>Movie</font></td><td><input type="text" size="60" name="movie"></td></tr> <tr><td><font color=red>Genre</font></td><td><input type="text" size="60" name="genre"></td></tr> <tr><td> </td><td><input type="submit" value="Send"><font face="arial" size="1"> Click Send To Continue</font></td></tr> </table> </form> <?php require_once 'http_build_query.php'; $Movie = file_get_contents('Movies.txt'); parse_str($Movie); if ($_POST['movie'] != '') { $na = count($Movie); $na = $na + 1; $Movie[$na][Title] = $_POST['movie']; $Movie[$na][Genre] = $_POST['genre']; $temp[Movie] = $Movie; $data1 = http_build_query($temp); $data = urldecode($data1); $file = fopen('Movies.txt', 'wb'); fwrite($file, $data); fclose($file); } foreach($Movie as $key => $val) { echo "$Movie[$key][Title] <br>"; } ?> I'm currently having problems just displaying the info. I have it written to a txt file and it looks like: Movie[1][Title]=The Da Vinci Code&Movie[1][Genre]=Drama / Mystery / Thriller&Movie[2][Title]=X-Men: The Last Stand&Movie[2][Genre]=Action / Adventure / Sci-Fi / Thriller I don't know if any of the above helps, but I certainly hope somebody can help me get to the bottom of this problem! Thank you very much in advance! Quote Link to comment https://forums.phpfreaks.com/topic/37003-so-lost-i-dont-know-where-to-start/ Share on other sites More sharing options...
kickassamd Posted February 4, 2007 Share Posted February 4, 2007 Honestly you should store stuff within a database like MySQL as working with flat files is confusing and time consuming. Quote Link to comment https://forums.phpfreaks.com/topic/37003-so-lost-i-dont-know-where-to-start/#findComment-176628 Share on other sites More sharing options...
xmanofsteel69 Posted February 4, 2007 Author Share Posted February 4, 2007 I'm trying to tackle one thing at a time...lol....Once I believe I'm pretty good at PHP, I'll head on over to the MySQL side of life and try my luck there. Quote Link to comment https://forums.phpfreaks.com/topic/37003-so-lost-i-dont-know-where-to-start/#findComment-176631 Share on other sites More sharing options...
JasonLewis Posted February 4, 2007 Share Posted February 4, 2007 try setting it up like this: <|>The Da Vinci Code|Drama/Mystery/Thriller<|>X-Men: The Last Stand|Action/Adventure/Sci-Fi/Thriller etc etc... just easy to handle, for me anyway. then your code would look like this: $movie = explode("<|>", file_get_contents("Movie.txt")); for($i = 0; $i < count($movie); $i++){ if($movie[$i] != ""){ list($title, $genre) = explode("|", $movie[$i]); echo "Title: {$title}<br>Genre: {$genre}<br><br>"; } } hope that does it for ya. EDIT: oops, that will display blanks as well. i have updated it to remove blanks. Quote Link to comment https://forums.phpfreaks.com/topic/37003-so-lost-i-dont-know-where-to-start/#findComment-176633 Share on other sites More sharing options...
xmanofsteel69 Posted February 4, 2007 Author Share Posted February 4, 2007 What I'm actually doing is writing it to the file, originally, and it's not really me who's setting it up like that. I'm using the http_build_query, or without the urldecode, it's quite a mess, so I just added that to make it readable in the txt file...and if I'm completely wrong...well...I'm still new to PHP...lol But yeah...I'm just wondering if there is a way to change this statement around foreach($Movie as $key => $val) { echo "$Movie[$key][Title] <br>"; } to make it display the info...I'm not 100% sure if you can or not. Quote Link to comment https://forums.phpfreaks.com/topic/37003-so-lost-i-dont-know-where-to-start/#findComment-176638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.