Reputation: 57
i'm making a simple site for movies and i wanna display related movies in the page.. the problem that my database contains American and Indian movies in movies table i'm trying to find a way that when the visitor click on any american movie the related movies would appear only the american movies (there is a column called "movie_lang" in my table that labels the american movies as number 1 and the indian as number 2) this's as far as i can get
$query=mysql_query("select * from movies order by id desc limit 4");
while($m=mysql_fetch_assoc($query)){
if($m['movie_lang']== '1'){
echo '<a href="view_movie.php?id='.$m['id'].'"><img src="uploads/poster/'.$m['thumbnail'].'" title="'.$m['name'].'"></a>' ;}
else{
echo '<div class="hidden"></div>"';
}
}
not sure of my code. sorry...new to this...
Upvotes: 1
Views: 44
Reputation: 720
Alright, I think I understand the issue, let me know if I missed it though: You want to list all types of movies, but if a user clicks a link for an american movie, you want to show him only american language movies on later pages. Here's my idea:
// When a page loads, it checks if the 'selected_lang' variable is set. If so, it creates a language filter
$previous_lang = isset($_GET['selected_lang'] && is_numeric($_GET['selected_lang'])) ? " where movie_lang = " . $_GET['selected_lang'] . " " : "";
// We assemble queries which will use a language filter if we have one, or all languages if not
$query=mysql_query("select * from movies $previous_lang order by id desc limit 4");
while($m=mysql_fetch_assoc($query)){
if($m['movie_lang']== '1'){
// We include a 'selected_lang' variable in our link, so that page now nows the language of the movie the user picked
echo '<a href="view_movie.php?selected_lang=1&id='.$m['id'].'"><img src="uploads/poster/'.$m['thumbnail'].'" title="'.$m['name'].'"></a>' ;
} else {
echo '<div class="hidden"></div>"';
}
}
This code looks to see if a 'selected_lang' was set, and if so, uses it for subsequent SQL queries. You may have to chop bits here and there for different pages, and possibly re-arrange it if you want to write your own (sensible) where clauses.
Let me know if you need more help with this.
Upvotes: 1
Reputation: 106
If you wanna display only the american movies because the visitor click on it, you can show all the american movies using your query database.
$query = mysql_query("select * from movies where movie_lang = 1 order by id desc limit 4");
If you want the indian movies, just change the parameter in movie_lang to 2. This parameter can be for you a GET request.
Upvotes: 1