How to create a dynamic table column in database php
view js
// ********************************************************
// **************************************************************
// * Save data from input Field *
// **************************************************************
$(document).ready(function() {
$('#submit').click(function(){
// alert(23);
$.ajax({
// alert(23);
url:"<?php echo base_url('sell/AddInputFieldCurrency')?>",
method:"POST",
data:$('#add_name').serialize(),
type:'json',
success:function(data)
{
i=1;
$('.dynamic-added').remove();
$('#add_name')[0].reset();
//alert('Record Inserted Successfully.');
}
});
});
});
controller // ********************************************************
// * AddInputFieldCurrency *
// ********************************************************
function AddInputFieldCurrency()
{
$currencyValue = $_POST['currencyValue'];
$currencyName = $_POST['currencyName'];
$data=array();
$i=0;
foreach($currencyValue as $key=>$value){
$str = $value;
$RemoveSpaceValue = str_replace(' ', '', $str); // space remove
$data['currencyValue']=$RemoveSpaceValue;
$data['currencyName']=$currencyName[$i];
$data['date']=date('Y-m-d');
$this->db->insert('currency',$data);
$i++;
}
$exististable = $this->db->table_exists('paddycash');
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "technodesk";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
if(!empty($exististable))
{
foreach($currencyName as $value)
{
$str = $value;
$RemoveSpaceValue = str_replace(' ', '', $str); // space remove
$sql = "ALTER TABLE paddycash ADD {$RemoveSpaceValue} VARCHAR(255)
NULL";
NULL";
$conn->query($sql);
}
}
}
Comments
Post a Comment