Please help! Creating query w/checkbox. Codes&files incl

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dr. Neko
Forum Newbie
Posts: 2
Joined: Mon Aug 18, 2003 2:45 pm
Location: NJ

Please help! Creating query w/checkbox. Codes&files incl

Post by Dr. Neko »

Hi.
I really need help on creating a dynamic SQL query (the link to the zip file of the source codes and sample files is in the bottom of this page). You can see what I'm doing in the "CheckGarfield.html" file. The visitor will select his/her selection in either the simple or advance search options. IE:

FROM
Select
either Daily Comics or Birthday Comics (each of these selections is the name of their table)

CHARACTERS
Garfield, Odie, John
(each of these is the name of their column in the tables above)

Basically, I created some tables. By default, when a CHARACTER isn't selected, it's value is set to "0" (false); it's value is set to "1" (true) when selected. Here's the table schema and sample value:

CREATE TABLE Daily
( Ino char(2) not null primary key,
URL char(15),
Tn char(17),
Garfield tinyint(2),
John tinyint(2),
Odie tinyint(2));



INSERT
INTO Daily(Ino, URL, Tn, Garfield, John, Odie)
VALUES ('1','"d/Daily01.gif"','"d/Daily01tn.gif"','1','0','0');
//the rest of the data is in the zip file

When the visitor makes a selection, he/she is actually customizing the query. Here's a sample of what the visitor will select and a sample of how the query should look like.

FROM
Select Daily Comics
(check) Birthday Comics (unchecked)

CHARACTERS
Garfield
(check) Odie (uncheck) John (check)

Code: Select all

$SQL="SELECT * FROM Daily where Odie=0 ORDER BY Ino";//want to achive this since the query is shorter
or

Code: Select all

$SQL="SELECT * FROM Daily where Odie=0 OR Garfield=1 OR John=1 ORDER BY Ino";//last resort since this vesion of the query is longer
When I modify the $SQL variables in the inc file and ran the page (such as the $SQL variable in lines 11 and 16 in the Daily.inc file in the Garfield folder), it works fine with that query.

The advance search, I've included a section:
SEARCH FOR

Any (this will be the "AND" variable)
Only (this will be the "OR" variable)

That's basically it. I just need to know how to make the $SQL variable dynamic with the selections above. I've included some php files (with sample images) that already work, some with the $SQL modified. I created a "Search.php" what includes some codes I made for the "CheckGarfield.html" file. Also, if you need further information for the "inc" files included, please look at the "Paginating.pdf" file --you can paste the codes in the "Search.php" into the "inc" file(s) if you want).
Finally, I was able to figure out how to prevent a search with none of the required selection(s) is/are selected, but is there a way to prevent illogical selections in the advance search, such as:
INCLUDES
Garfield (check)


NOT INCLUDING
Garfield (check)


If you can figure anything out, please let me know. Thank you.

-Daniel Orellana

LINK TO SOURCE CODES & SAMPLE FILE:
"SorceCodes&Samples.zip":
Post Reply