Jump to content

So lost I don't know where to start...


xmanofsteel69

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/37003-so-lost-i-dont-know-where-to-start/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.