Php - Filtering Data In Table
Solution 1:
$result = mysql_query("SELECT * FROM Colors WHERE color='Red'");
Solution 2:
When the user chooses a color, redirect him on the same page with a $_GET variable containing the color he has choosen. Then, check in your code if the $_GET variable containing the color exist :
if(isset($_GET['color']))
result = mysql_query("SELECT * FROM Colors WHERE color='".htmlentities($_GET['color'])."'");
else
result = mysql_query("SELECT * FROM Colors");
Solution 3:
You will need to create a form containing a list box containing a list of colours that the user can pick from. In turn that form will need to post a variable back to the page that PHP will then give to MySQL to filter the result table.
Filtering the result table alone to just red would be done using :
$result = mysql_query("SELECT * FROM Colors WHERE color='Red'");
However to filter that based on a form posting to the page would require something like this:
$result = mysql_query("SELECT * FROM Colors WHERE color='".mysql_escape_string($_REQUEST['color'])."'");
Where "color" is the name of the variable that has been posted to the page containing the name of the colour you wish to filter by.
Solution 4:
I know I'm way too late but maybe there are still people looking for a solution. All i know about this case is that you simply
$result = mysql_query("
SELECT * FROM database_name
WHERE Color LIKE 'Red%'
");
Solution 5:
I am pretty sure you're looking for "this". You need JavaScript for that to work.
There are basically 3 steps:
- Make an HTML table to display contents.
- Use CSS to style that table.
- Use JavaScript for searching and filtering the table.
See more on the link provided. https://www.w3schools.com/howto/howto_js_filter_table.asp
Post a Comment for "Php - Filtering Data In Table"