0
votes

I'm looking to give my users an option from a drop down menu to select which query they want to run and then when clicked on the menu triggers the query to run. I'm thinking something like....

Name-----Address----Sales Person----Full Report--

So for example if the user clicked the full report option from the menu it would trigger this query.

'SELECT DISTINCT jsfdName.baseData AS Name, jsfdAddr.baseData as Address, 
jsfdZip.baseData   AS Zip, jsfdCity.baseData AS City, jsfdState.baseData AS State,   
jsfdEmail.baseData AS Email,jsfdPhone.baseData AS Phone, jsfdPerson.baseData AS Person, 
jsfdContacted.baseData AS Contacted
FROM jos_sobipro_field_data AS jsfdName
JOIN jos_sobipro_field_data AS jsfdAddr USING(sid)
JOIN jos_sobipro_field_data AS jsfdZip USING(sid)
JOIN jos_sobipro_field_data AS jsfdCity USING(sid)
JOIN jos_sobipro_field_data AS jsfdState USING(sid)
JOIN jos_sobipro_field_data AS jsfdEmail USING(sid)
JOIN jos_sobipro_field_data AS jsfdPhone USING(sid)
JOIN jos_sobipro_field_data AS jsfdPerson USING(sid)
JOIN jos_sobipro_field_data AS jsfdContacted USING(sid)
WHERE jsfdName.fid = 36 AND jsfdAddr.fid = 37 AND jsfdZip.fid=38 AND jsfdCity.fid = 39     
AND jsfdState.fid = 41 AND jsfdEmail.fid = 65 AND jsfdPhone.fid = 46 AND jsfdPerson.fid  
= 66 AND jsfdContacted.fid = 63 AND sid > 900';

Any ideas? I'm trying to do this all in one file too because I want it to be password protected so that only users can access it. Thanks for the help guys.

1
What do you mean by "all in one file"? You want all of your UI, business logic, data logic, and anything else you can think of all stuffed into one file? I recommend against that. - David
My question is how do I tell the file that when the drop down menu is selected by the user to run the above query? I'll be having different queries for the different options. And @David by all in one file I don't mean absolutely everything. I'd just like to contain the queries and form data in one file instead of separating them. - h3tr1ck
@JustinHetrick: It sounds like you're looking for a tutorial on how to write a website in PHP. We don't really give tutorials here, Google is your friend in that case. If you have a specific question about the code or a specific problem you're facing, we can help with that. But if your question is "how do I write something in PHP?" then that's just too broad here. - David

1 Answers

2
votes

I'll assume you know the basics of php, html, and sql. I'll just tell you how to choose which query.

For the html, I'd use this for the dropdown:

<select name="report">
    <option value="1">Full Report</option>
    <option value="2">Some Other Report</option>
</select>

You can repeat that with different values as much as needed.

Now for the php (selecting the query):

<?php
switch($_POST['report']) {
    case "1":
        $query = "SOME QUERY TEXT WOULD GO HERE";
        break;
    case "2":
        $query = "TEXT FOR A DIFFERENT QUERY HERE";
        break;
    default:
        //DO SOMETHING HERE IF THE VALUE IS NOT RECOGNIZED
        break;
}
//NOW RUN THE QUERY WITH $query as the string
?>

You can add as many cases as you need to meet your need.