...

View Full Version : Problem with selecting by category



maikelv
02-26-2008, 06:20 PM
Hi there,

I have the following problem : I have a script wich catalogues my movies.
I want to be able to view them by genre but also to view them all in one list.
The problem I'm having is : It always returns all the movies.

The form :

<form action="verwerk.php?action=view" method="post">
Genre: <br />
<select name="genre">
<option value="alles">Alles</option>
<?php
if ($result=$link->query($query)) {
for ($i=0; $i < $result->num_rows; $i++) {
$rij= $result->fetch_assoc();
print("<option value=\"{$rij['id']}\">{$rij['genre']}</option>\n");
}
$result->close();
}
?>
</select><br />
<input type="submit" class="button" value="Bekijk" />
</form>


And the PHP




case view:
if ($_POST['genre']="alles") {
$query = "SELECT *
FROM divx INNER JOIN genres ON genreid=genres.id";

}
else {
$query = "SELECT *
FROM divx INNER JOIN genres ON genreid=genres.id
WHERE \"{$_POST['genre']}\"=genreid";
}
?>
<table class="result">
<tr>
<td class="top">Titel</td>
<td class="top">Genre</td>
</tr>
<?php
if ($result=$link->query($query)) {
for ($i=0; $i < $result->num_rows; $i++) {
$rij= $result->fetch_assoc();
print("<tr>\n");
print("<td class=\"cell1\">{$rij['titel']}</td>\n");
print("<td class=\"cell2\">{$rij['genre']}</td>\n");
print("</tr>\n");

}
$result->close();
}
$link->close() or die("Kan link met $dbserver niet sluiten.");
?>
</table>
<a href="film.php">Terug</a>
<?php
break;

Has anyone got any idea ?

meth
02-26-2008, 07:44 PM
Try:



$query = "SELECT *
FROM divx INNER JOIN genres ON genreid=genres.id
WHERE genreid = '".mysql_real_escape_string($_POST['genre'])."'";
}

maikelv
02-27-2008, 02:08 PM
Try:



$query = "SELECT *
FROM divx INNER JOIN genres ON genreid=genres.id
WHERE genreid = '".mysql_real_escape_string($_POST['genre'])."'";
}



Thanks, but it yields the same result. I'm thinking something is going wrong in the if/else function. I can't seem to find the problem though.

PappaJohn
02-27-2008, 02:17 PM
($_POST['genre']="alles")
This line is NOT checking the value of $_POST['genre']. To do so, use:

($_POST['genre'] == "alles")

== is a comparison operator, = is an assignment operator

maikelv
02-29-2008, 09:04 AM
($_POST['genre']="alles")
This line is NOT checking the value of $_POST['genre']. To do so, use:

($_POST['genre'] == "alles")

== is a comparison operator, = is an assignment operator


gee, do I feel stupid =D
It works now, thanks alot !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum