944,051 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 8951
  • PHP RSS
Feb 8th, 2006
0

Multiple queries within one php file

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
markmuir_8 is offline Offline
1 posts
since Feb 2006
May 8th, 2006
0

Re: Multiple queries within one php file

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
Reputation Points: 15
Solved Threads: 0
Junior Poster in Training
barnamos is offline Offline
50 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: RE:project stuff
Next Thread in PHP Forum Timeline: Multiple Counters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC