Hi Friends,
We have Just Implemented the New Input Types for India for All Developers. Before This is a very Big task to Add State, District & Block in any type of Form like Student registration, membership, admission, job apply etc.
I am going the share You some Functions, SQL File that help you to create Your Dynamically.
FUNCTION TO CRAETE LIST
function create_list($table_name, $field, $whereArr = null)
{
global $con;
$cols = array();
if ($whereArr != null) {
foreach((array)$whereArr as $key => $value) {
$newvalue = preg_replace('/[^A-Za-z.@,:+0-9\-_]/', ' ', $value);
$where[] = "$key = '$newvalue'";
}
$sql = "select distinct($field) from " . $table_name . " WHERE " .
implode('and ', $where) ." order by ". $field;
} else {
$sql = "select distinct($field) from " . $table_name ." order by ". $field;
}
$res = mysqli_query($con, $sql) or die(" Error in creating List : " .
mysqli_error($con));
if (mysqli_num_rows($res) >= 1) {
while ($row = mysqli_fetch_assoc($res)) {
$list[] = $row[$field];
}
} else {
return null;
}
return $list;
}
function state_list()
{
return create_list('op_sdb', 'state');
}
function district_list($state='bihar')
{
return create_list('op_sdb', 'district',['state'=>$state]);
}
function block_list($district='saran')
{
return create_list('op_sdb', 'block',['district'=>$district]);
}
SQL FILE
Comments
Post a Comment
Comment your offer ...