| | |
Multiple queries within one php file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2006
Posts: 1
Reputation:
Solved Threads: 0
Hi guys, i'm having a major problem with producing queries using PHP. By the way, not that good at trying to explain problem!!
I want to be able to run queries within a PHP form without having to input values into every fields(meaning searching the database for field1, fields2, field4 & field5 whilst field 3, field 6 & field 7 are empty). There are 7 fields. An example of what I'm looking for is:-
If a user wants to know how many males, in Year 2 walk to school and thinks that the roads are busy.
The names of the fields are:- gender, yeargroup, walkcycle, bustrain, crossbusyroads, school, security.
P.s Using MySQL database
Any help at all would be greatly appreciated.
I want to be able to run queries within a PHP form without having to input values into every fields(meaning searching the database for field1, fields2, field4 & field5 whilst field 3, field 6 & field 7 are empty). There are 7 fields. An example of what I'm looking for is:-
If a user wants to know how many males, in Year 2 walk to school and thinks that the roads are busy.
The names of the fields are:- gender, yeargroup, walkcycle, bustrain, crossbusyroads, school, security.
P.s Using MySQL database
Any help at all would be greatly appreciated.
Seems like you could build your query according to what it entered. I take it you are having trouble because field 7 might be blank and you don't want to search for a blank field 7, you want to ignore field 7?
So just do a:
if ($_POST["gender"]) $qry.="gender='". $_POST["gender"]."',";
for each field.
Note the .= which keeps adding each part to the query.
Then trim the last comma off and use $qry as your query.
Good luck
So just do a:
if ($_POST["gender"]) $qry.="gender='". $_POST["gender"]."',";
for each field.
Note the .= which keeps adding each part to the query.
Then trim the last comma off and use $qry as your query.
Good luck
![]() |
Similar Threads
- Need help with changing the index.php file (Existing Scripts)
- Can we execute command line cmds from a php file?? (PHP)
- PHP file calling html control names (PHP)
- PHP5x,Apache2.2 : Apache not reading php file (PHP)
- PHP file displaying wrongly ??? (PHP)
- IIS & PHP Setup-Configuring for multiple sites (Windows Servers and IIS)
- Get the name of the current php file (PHP)
- What is the purpose of the "lib.php" file?? (PHP)
Other Threads in the PHP Forum
- Previous Thread: RE:project stuff
- Next Thread: Multiple Counters
| Thread Tools | Search this Thread |
.htaccess alexa apache api array beginner beneath binary broadband broken cakephp checkbox class cms code convert cron curl database date display dynamic echo email encode error explodefunction fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert ip javascript joomla key keywords limit link login mail mail() memberships menu mlm multiple multipletables mysql mysql_real_escape_string network oop open passwords paypal pdf php provider query radio random redirect remote rss script search securephp server sessions smtp source space sql strip_tags syntax system table template tutorial update upload url user validator variable video voteup web youtube





