Popular Posts

Oct 16, 2011

Search in PHP

Create a file activities_report.php

<form action="activities_report.php" method=POST>
<table border="0" width="100%">
<tr>

</tr>
</form>


<?php
require_once 'search_functions.php';
$cond = build_activities_filter_conditions(&$_POST);

$selectSQL = "SELECT
`activities`.`activities_id`,
`activities`.`suit_no`  as suit_no,
`activities`.`activities_date`,
`activities`.`details`,
`activities`.`next_activities_date`,
`activities`.`action_details`,
`activities_type`.`activities_type`,
`ulis_info`.`ulis_name` as ulis_name,
`activities`.`activity_type`,
`activities`.`next_activities_type`
FROM
`activities`
Inner Join `activities_type` ON `activities`.`activity_type` = `activities_type`.`activities_type_id`
Inner Join `ulis_info` ON `activities`.`ulis_info_id` = `ulis_info`.`ulis_info_id`
WHERE $cond
";

$rec = query($selectSQL);
$sl=0;


Then Create another file named it search_functions.php

function build_activities_filter_conditions($var,$alis_name=''){
    $ret = ' 1 ';
    extract($var);
    $ret .= ($from_date!="") ? " AND ".$alis_name."activities_date>='$from_date'" : "";
    $ret .= ($to_date!="") ? " AND ".$alis_name."activities_date<='$to_date'" : "";
    $ret .= ($ulis_no!="") ? " AND ".$alis_name."ulis_name LIKE '$ulis_no%'" : "";
    $ret .= ($suit_no!="") ? " AND ".$alis_name."suit_no='".$suit_no."'" : "";
    $ret .= ($activites_type!="") ? " AND ".$alis_name."activity_type='$activites_type'" : "";
        
    return $ret;
}


No comments:

Post a Comment