| | |
Advanced mySQL Querys
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2004
Posts: 1
Reputation:
Solved Threads: 0
Hi, im new to the forums and i hope you wont mind me launching in with a big question!
Ii am currently prototyping a multimedia information
system which holds wakeboarding images and videos, along
with a comprehensive set of meta-data about the multimedia
data. Users can query the metadata in the database extensivly to return relevant pictures/videos. (ie. search by wakeboarder, lake , date taken etc.)
This is an online system, using mySQL for the
meta-data-database and PHP to work with it.
I put the database in 1st normal form. Meaning that my data
is now stored across 14 separate relational tables, no
repeating fields... and 10 line SQL querys with about 7
inner joins
. Being lazy i made a duplicate database in
Access and have been using this to generate SQL commands
that would otherwise make my head explode .
A quick think and i come across this problem (being
relatively new to database design). I want to query
anywhere between 1 and 8 fields at a time from a single PHP
Search form.
Ideally i will be blissfully unaware of a very simple "one
template" solution i can use to get results from the
database i need... to further explain ...
i was hoping to utilise one standard SQL command template
which takes user inputted values from a PHP form and querys
the DB with those values, but ignores the blank ones. From
using my access model, it seems that if i search for a
blank ( eg. "" as criteria) along with some valid search
criteria i know to give a result (such as 22 for RiderAge or Mike for RiderName )
it returns no result. however the same search with a
*completely empty box* (instead of "") for the blank fields
returns me standard results.
Is this simply just an access thing? when i send a $string
to mySQL database from the PHP form containing nothing will it act as if i
queried "" or left it blank?
Cause other wise i need to write 92 separate templates
( 8
+7+6+5+4+3+2+1
+6+5+4+3+2+1... etc. )
THe only way around this if i am stuck i can see would be
to create a stupidly long php script for the search page
with 92 Separate SQL Command Templates, and write an
algorithm decide which to use based on which criteria had
been entered and which left blank, which to me, sounds like
a lot of work. (Do-able, but would eat an entire afternoon)
I hope this makes sense and some-one can tell me an better
solution!
Cheers!
Ii am currently prototyping a multimedia information
system which holds wakeboarding images and videos, along
with a comprehensive set of meta-data about the multimedia
data. Users can query the metadata in the database extensivly to return relevant pictures/videos. (ie. search by wakeboarder, lake , date taken etc.)
This is an online system, using mySQL for the
meta-data-database and PHP to work with it.
I put the database in 1st normal form. Meaning that my data
is now stored across 14 separate relational tables, no
repeating fields... and 10 line SQL querys with about 7
inner joins
. Being lazy i made a duplicate database inAccess and have been using this to generate SQL commands
that would otherwise make my head explode .
A quick think and i come across this problem (being
relatively new to database design). I want to query
anywhere between 1 and 8 fields at a time from a single PHP
Search form.
Ideally i will be blissfully unaware of a very simple "one
template" solution i can use to get results from the
database i need... to further explain ...
i was hoping to utilise one standard SQL command template
which takes user inputted values from a PHP form and querys
the DB with those values, but ignores the blank ones. From
using my access model, it seems that if i search for a
blank ( eg. "" as criteria) along with some valid search
criteria i know to give a result (such as 22 for RiderAge or Mike for RiderName )
it returns no result. however the same search with a
*completely empty box* (instead of "") for the blank fields
returns me standard results.
Is this simply just an access thing? when i send a $string
to mySQL database from the PHP form containing nothing will it act as if i
queried "" or left it blank?
Cause other wise i need to write 92 separate templates
( 8
+7+6+5+4+3+2+1
+6+5+4+3+2+1... etc. )
THe only way around this if i am stuck i can see would be
to create a stupidly long php script for the search page
with 92 Separate SQL Command Templates, and write an
algorithm decide which to use based on which criteria had
been entered and which left blank, which to me, sounds like
a lot of work. (Do-able, but would eat an entire afternoon)
I hope this makes sense and some-one can tell me an better
solution!
Cheers!
•
•
Join Date: Oct 2004
Posts: 14
Reputation:
Solved Threads: 1
Hello typedef,
I don't know if I have understand all of your problem, here a way to constroy a SQL with various fields
fpepito
######## http://www.fpepito.org/php/test6.php
[PHP]
<?
if (!isset ($autor)) {
echo "<FORM ACTION=$PHP_SELF>\n";
echo "Autor : <INPUT TYPE=TEXT NAME=autor VALUE=Pepito><BR>\n";
echo "Text : <INPUT TYPE=TEXT NAME=text VALUE=port><BR>\n";
echo "After date : <INPUT TYPE=TEXT NAME=aft VALUE=2002-01-01><BR>\n";
echo "Before date : <INPUT TYPE=TEXT NAME=bef VALUE=2004-01-1><BR>\n";
echo "<INPUT TYPE=submit value=\"Identify\">\n";
echo "<BR><HR><BR>\n";
echo "</FORM>\n";
} else {
include "/home/httpd/html/PHP/connect.php";
connect_mysql();
$criteria = "";
if (isset ($autor) && !($autor == "")) {
$criteria .= " autor = '$autor'";
}
if (isset ($text) && !($text == "")) {
if (! ($criteria == "")) {$criteria .= " AND "; }
$criteria .= " desc_pt LIKE '%$text%'";
}
if (isset ($aft) && !($aft == "")) {
if (! ($criteria == "")) {$criteria .= " AND "; }
$criteria .= " data > '$aft'";
}
if (isset ($bef) && !($bef == "")) {
if (! ($criteria == "")) {$criteria .= " AND "; }
$criteria .= " data < '$bef'";
}
if (!($criteria == "")) {
$criteria = "WHERE ". $criteria;
}
$q = "SELECT * FROM fotos_file $criteria";
echo "$q<BR>\n";
$query = mysql_query ($q);
$res = mysql_num_rows($query);
echo "<BR>I found $res element corresponding of your demand";
}
?>
[/PHP]
I don't know if I have understand all of your problem, here a way to constroy a SQL with various fields
fpepito
######## http://www.fpepito.org/php/test6.php
[PHP]
<?
if (!isset ($autor)) {
echo "<FORM ACTION=$PHP_SELF>\n";
echo "Autor : <INPUT TYPE=TEXT NAME=autor VALUE=Pepito><BR>\n";
echo "Text : <INPUT TYPE=TEXT NAME=text VALUE=port><BR>\n";
echo "After date : <INPUT TYPE=TEXT NAME=aft VALUE=2002-01-01><BR>\n";
echo "Before date : <INPUT TYPE=TEXT NAME=bef VALUE=2004-01-1><BR>\n";
echo "<INPUT TYPE=submit value=\"Identify\">\n";
echo "<BR><HR><BR>\n";
echo "</FORM>\n";
} else {
include "/home/httpd/html/PHP/connect.php";
connect_mysql();
$criteria = "";
if (isset ($autor) && !($autor == "")) {
$criteria .= " autor = '$autor'";
}
if (isset ($text) && !($text == "")) {
if (! ($criteria == "")) {$criteria .= " AND "; }
$criteria .= " desc_pt LIKE '%$text%'";
}
if (isset ($aft) && !($aft == "")) {
if (! ($criteria == "")) {$criteria .= " AND "; }
$criteria .= " data > '$aft'";
}
if (isset ($bef) && !($bef == "")) {
if (! ($criteria == "")) {$criteria .= " AND "; }
$criteria .= " data < '$bef'";
}
if (!($criteria == "")) {
$criteria = "WHERE ". $criteria;
}
$q = "SELECT * FROM fotos_file $criteria";
echo "$q<BR>\n";
$query = mysql_query ($q);
$res = mysql_num_rows($query);
echo "<BR>I found $res element corresponding of your demand";
}
?>
[/PHP]
![]() |
Similar Threads
- another MySQL question ? (PHP)
- Multiple text box query (PHP)
- REWARD! Help me find a PHP/mySQL DEVELOPER needed (Web Development Job Offers)
- PHP Login Help? (PHP)
- get sets of info from db depending on hidden field's value (PHP)
- Double MySQL Query (PHP)
- Advanced PHP MySQL Programmer wanted (Web Development Job Offers)
- Passing variables into form fields (PHP)
Other Threads in the PHP Forum
- Previous Thread: I had a experience of a website coded in PHP
- Next Thread: php project help
| Thread Tools | Search this Thread |
301 access apache api array beginner binary broken button cakephp checkbox class clean cms code compression countingeverycharactersfromastring crack cron curl database date decode directory display dissertation dropdown dynamic echo email error fairness file files folder form forms function functions google href htaccess html httppost image include insert integration ip javascript joomla limit link login mail match md5 menu methods mlm multiple mysql newsletters oop pageing pagerank paypal pdf php protocol query radio random recursion remote script search secure server sessions simple soap source space spam sql syntax system table tutorial update upload url validator variable video virus votedown web youtube





