Home > Archive > PHP SQL > October 2004 > Newbie help please
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newbie help please
|
|
| Steve O 2004-10-15, 3:57 pm |
| I'm very new to this, and here's another question relating to a site showing
paitings by my wife.
Here's what I want to do:
My page has an HTML form with 4 checkboxes like this:
<input type="checkbox" name="red" value="red"> Red
<input type="checkbox" name="blue" value="blue"> Blue
<input type="checkbox" name="green" value="green"> Green
<input type="checkbox" name="yellow" value="yellow"> Yellow
And when I click 'Submit' this happens:
<form action="galleryselect.php" method="post">
Trouble is, I can't write the 'galleryselect' function because I'm hopeless.
I have already got a working MySQL database that I can display results from,
but I can't take the next step of interacting with a users choices.
The database includes a column called 'red' one called 'blue' etc.....
If a painting has Red in it, there's a 'y' (for yes) in the 'red' column. If
it has Blue as well, then there's a 'y' in the 'blue' column.....etc
I need a user to check a box in the form, and have MySQL return any
paintings that have the chosen colour in. If they choose two colours, then
only paitings with both of those colours are returned and so on.
I'm not expecting anyone to write this script for me, but a pointer to a
tutorial would be great. I've Googled with little luck :-(
--
#Reply address#
steve_at_steveolive_dot_co_dot_uk
| |
| Hilarion 2004-10-15, 3:57 pm |
| I assume that all the checkbox HTML tags are within form tag.
In 'galleryselect.php' you can check if a checkbox was checked by
referring to the $_POST (or $_REQUEST) table (check if your
version of PHP has it, if not, then check PHP manual for it's
predecessors) like this:
if (isset($_POST['red']) && ($_POST['red']!=''))
do_something();
Use this info to create proper SQL query like this:
$query = 'SELECT * FROM pictures';
$where_clause = array();
foreach( array( 'red', 'green', 'blue', 'yellow' ) as $color )
{
if (isset($_POST[$color]) && ($_POST[$color]!=''))
$where_clause[] = $color . " = 'y'";
}
if (count( $where_clause ))
{
$where_clause = implode( ' AND ', $where_clause );
$query .= ' WHERE ' . $where_clause;
}
You allready know how to use PHP MySQL functions to retrieve
the query results and display them.
Hilarion
| |
| Steve Olive 2004-10-15, 8:55 pm |
| From my other account........
Sorry, but I understand very little of that.
I'm going to try and find a local educational establishment that can teach
MySQL/PHP as I am struggling here.
I'm probably trying to run before I can walk, and that ain't good.
Cheers for you help though, it taught me enough to know my next step.
| |
|
| On Fri, 15 Oct 2004 22:05:14 +0100, "Steve Olive"
<steve@steveolive.co.uk> wrote:
>From my other account........
>
>Sorry, but I understand very little of that.
>
>I'm going to try and find a local educational establishment that can teach
>MySQL/PHP as I am struggling here.
>
>I'm probably trying to run before I can walk, and that ain't good.
>
>Cheers for you help though, it taught me enough to know my next step.
>
Following are 2 sites that teach php and other stuff for free. They
are easy tutorials.
http://www.tizag.com/phpT/
http://www.w3schools.com/
|
|
|
|
|