Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple Filter in PHP or MySQL

Posted on 2007-10-10
1
Medium Priority
?
1,848 Views
Last Modified: 2013-12-13
Hi,

I'm making a simple movie catalog database.  I want to add a filtering option on the catalog but I'm not sure how to do it properly.

Here my query to output the data:

==================================================================
$query  = "SELECT * FROM movies_view ORDER BY `title` ASC";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$id = $row["id"];
$title = $row["title"];
$owner = $row["owner"];
$type = $row["type"];
$imdb = $row["imdb"];
$region = $row["region"];

$row_color = ($row_count % 2) ? $color1 : $color2;

if ($imdb == "")
{

echo   "<tr bgcolor=\"$row_color\" class=\"content_rows\">
            <td width=\"20\" align=\"center\">$row_number</td>
            <td width=\"20\" align=\"center\"><img src=\"no.png\" width=\"16\" height=\"16\" border=\"0\"></td>
            <td width=\"420\">$title</td>
            <td width=\"80\" class=\"content_rows\">$owner</td>
            <td width=\"30\" class=\"content_rows\" align=\"center\">$type</td>
            <td width=\"30\" class=\"content_rows\" align=\"center\">$region</td>
            </tr>";
}

else

echo   "<tr bgcolor=\"$row_color\" class=\"content_rows\">
            <td width=\"20\" align=\"center\">$row_number</td>
            <td width=\"20\" align=\"center\"><a href=\"$imdb\" target=\"_blank\"><img src=\"yes.png\" width=\"16\" height=\"16\" border=\"0\"></a></td>
            <td width=\"420\">$title</td>
            <td width=\"80\" class=\"content_rows\">$owner</td>
            <td width=\"30\" class=\"content_rows\" align=\"center\">$type</td>
            <td width=\"30\" class=\"content_rows\" align=\"center\">$region</td>
            </tr>";

$row_count++;
$row_number++;
      
}

echo "</table>";
==================================================================

I've done a DISTINCT query to create a dropdown list of 'owner' I would like to have the option that when I select the owner in the dropdown menu that it will just output that specific owner.

thanks for your help!
0
Comment
Question by:jambla
1 Comment
 
LVL 28

Accepted Solution

by:
gamebits earned 1500 total points
ID: 20054176
Basically you would have to capture the variable from the form and use this variable in a where clause.

$owner = $_POST['owner'];

SELECT * FROM movies_view WHERE owner = '$owner' ORDER BY `title` ASC
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question