HTML下拉查询

时间:2012-05-21 15:57:47

标签: php html sql database

我希望从下拉菜单中为我的用户提供一个选项,以选择他们想要运行的查询,然后在菜单上单击时触发查询运行。我在想像......

姓名-----地址----销售人员----完整报告 -

因此,例如,如果用户从菜单中单击完整报告选项,则会触发此查询。

'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';

有什么想法吗?我也试图在一个文件中完成所有操作,因为我希望它受密码保护,以便只有用户才能访问它。谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

我假设你知道php,html和sql的基础知识。我只是告诉你如何选择哪个查询。

对于html,我会将其用于下拉列表:

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

您可以根据需要使用不同的值重复此操作。

现在为php(选择查询):

<?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
?>

您可以根据需要添加尽可能多的case