how to get string 'Sugar&Jaggery, Salt' via <a> in codeigniter? - javascript

plz anyone me i m beginner in codeigniter in herf passing url with string but the whole can't get in
controller & can't accepting as sting so what shold i do for it plz someone help me
//Here is html code which pass sting value
index.php/Home/product_show?type='Sugar&Jaggery , Salt'">Sugar & Jaggery , Salt
//controller get sting in type variable but on Sugur got not whole sting and pass type variable to model
public function product_show(){
$type = $_GET['type'];
die(var_dump($type));
$data['testdata']= $this->Globle_model->get_multiple_record($type);
$this->load->view('display_product',$data);
}
//model type variable check the subcategory from database and return to controller
public function get_multiple_record($type){
$this->db->where_in('Subcategory_name',$type);
$get_data = $this->db->get('productmaster');
return $get_data->result_array();
}
//o/p
get this much of string(6) "'Sugar"

Please follow the below way to get all your string into the controller into
$_GET['type'] variable.
Combine all your strings into a single variable using _ into href
Example :
Sugar & Jaggery , Salt
In the controller, I have created one array() with variable subcategory_type .In which key is coming from the view but its value from the database.
Example :
function get_product_type(){
$get_info = $this->input->get();
$subcategory_type = array(
"Sugar_Jaggery_Salt" => "Sugar&Jaggery , Salt"
);
$type_arr = $subcategory_type[$get_info['type']];
$data['testdata']= $this->Globle_model->get_multiple_record($type_arr);
$this->load->view('display_product',$data);
}
In model,
function get_multiple_record($type_array){
$this->db->where_in('Subcategory_name',$type_array);
$get_data = $this->db->get('productmaster');
return $get_data->result_array();
}
Try this and update me in case of anything.

Related

Trying to pass an array variable from asp to javascript

trying to pass an array variable to java
The following is not working, any idea why and how to make it work
Code behind
Public myArray (5) As String
myArray(1) = "A1"
myArray(2) = "A2"
myArray(3) = "A3"
myArray(4) = "A4"
myArray(5) = "A5"
In asp
<button type = "button" onclick="myJava('<%= myArray %>');">Search</button>
In Javascript
function myJava (myArray) {
alert(myArray[1]); // expected answer is A1 but it is not
}
You need to properly encode your array. Firstly, you need to convert it to a JSON string; then you need to encode that string as an HTML attribute value.
Add a reference to the Newtonsoft.Json NuGet package. Add an Imports statement for the Newtonsoft.Json namespace. Add a method to your code-behind to return the properly-encoded function call:
Public Function PassArrayToJavascript(ByVal functionName As String) As String
Dim json As String = JsonConvert.SerializeObject(myArray)
Dim result As String = functionName + "(" + json + ");"
Return System.Web.HttpUtility.HtmlAttributeEncode(result)
End Function
Then update your markup to call this function:
<button type = "button" onclick="<%= PassArrayToJavascript("myFunction") %>">Search</button>

How to put a string to make a query using PHP CodeIgniter

I have different strings that is made by multiple checkboxes when is checked and I would like to use this strings to make a query.
For example:
If I click a specific sequence of checkboxes this returns me this value of string: "SELECT Call_Setup FROM lte_kpi.vw_main_kpis_cidade_rate_daily WHERE node != 'UNKNOWN' and node = 'ABADIA DE GOIÁS' and date between '10/02/2017' and '10/18/2017' order by date"
I save this query into a variable called query1. What I would like is to put this variable (query1) like parameter to perform a query.
This is my model:
<?php
class Model_KPI_Customize extends CI_Model{
function kpi_customize_CustomQuery(){
$query = $this->db->query(/*I would like to put my string here !*/);
return $query->result();
}
}
?>
This is my Controller
public function highcharts_teste(){
$this->load->model('model_kpi_customize');
$data['kpi_customize_string_CustomQuery'] = $this->model_kpi_customize
->kpi_customize_CustomQuery();
}
And I have a view with multiple checkboxes and one paragraph element wich I would like to display the result of a query.
In the example above I would like to return the following values like this, because this is the result when I query it on Database:
99.73
99.48
99.51
99.40
99.23
99.34
99.29
99.10
99.23
99.11
Thanks everyone.
Bye =)
SELECT Call_Setup
FROM
lte_kpi.vw_main_kpis_cidade_rate_daily
WHERE
node != 'UNKNOWN' and
node = 'ABADIA DE GOIÁS' and
date between '10/02/2017' and '10/18/2017'
order by date
Can be written using active_record like below
$where = array(
'node' => 'ABADIA DE GOIÁS',
'date >=' => '10/02/2017',
'date <=' => '10/18/2017'
);
$this->db->select('Call_Setup')
->get_where('vw_main_kpis_cidate_rate_daily', $where )
->order_by("date", "asc");

javascript object.key not working

I have code to get GA parameters that have been stored in a cookie and make them the values of inputs in a form that isn't working and I can't for the life of me figure out why.
(function( $ ) {
if (Cookies.get('gaParams')) {
var params = Cookies.get('gaParams');
}
$('#source').val(params['utm_source'] ? params['utm_source'] : 'organic');
$('#medium').val(params['utm_medium'] ? params['utm_medium'] : '');
$('#campaign').val(params['utm_campaign'] ? params['utm_campaign'] : '');
$('#keywords').val(params['utm_terms'] ? params['utm_terms'] : '');
console.log(params,params['utm_medium'],params.utm_medium);
}(jQuery));
you can see it in action by going here and then clicking on the "request Quote" button.
The console.log will return {"utm_medium":"testing","utm_source":"whatever"} undefined undefined
I don't understand why calling the object keys won't give me the values this way.
Because the variable params is string type . You should use this method JSON.parse() to parse a JSON string
var params = Cookies.get('gaParams');
params = JSON.parse(params);

How can I get serializableArray jQuery that contains one array object in php?

How can i get my object array serializable in jquery to php ?
I have this:
I need get this array sent by jQuery(vetDespesas) in php to create my sql query.
I try use dump php serialize, unserialize but it won't work.
I use this in jQuery:
// this = my Form html
var dataSend = $(this).serializeArray(); // other datas...
dataSend.push({name:'moeda',value:moeda});
dataSend.push({name:'moedaCotacao',value:moedaCotacao});
**dataSend.push({name:'vetDespesas',value:vetDespesas});** object array
and in php, how can I write the code?
$requisitadopor = $_POST['requisitadopor'];
$autorizadopor = $_POST['autorizadopor'];
$departamento = $_POST['departamento'];
$unidade = $_POST['unidade'];
var_dump($_POST['vetDespesas']); // doesn't work =/ (array of objects)
vetDespesas = JSON.stringify(vetDespesas);
and i php use:
$a = json_decode($_POST['vetDespesas']);
var_dump($a[0]);
My chrome console print:
object(stdClass)[2]
public 'dataDespesa' => string '15/12/2015' (length=10)
public 'descDespesa' => string 'teste1' (length=6)
public 'budgetDespesa' => string '001 001 0E2R' (length=12)
public 'valorDespesa' => string '2133.33' (length=7)
How can I access this data?
You should turn it into a JSON string before send it to PHP :
vetDespesas = JSON.stringify(vetDespesas);
And to get the object in PHP code you should use json_decode() :
$my_object = json_decode($_POST['vetDespesas']);
You can access to object(stdClass) attributes using ->, e.g :
echo $my_object->dataDespesa;
echo $my_object->budgetDespesa;
Hope this helps.

convert param to JSON data inside URL

I have a URL like that and I want to use JSON data coming inside URL
"CUNMXSAKU" : {
"roomCodes" : "DEAL, JRST, JPOV, JSSW, PJRS, PJOV, PJSW, RMOV, RMOF, PRES"
},
My URL
...._results.html?language=en&hotelInfo={CUNMXSAKU:{roomCodes:DEAL,JRST,JPOV,JSSW,PJRS,PJOV,PJSW,RMOV,RMOF,PRES}}
Is it possible to use it ?? I am able to get
var hotelCode = getQueryParameter('hotelInfo');
as a String
{"CUNMXSAKU":{"roomCodes":"DEAL, JRST, JPOV, JSSW, PJRS, PJOV, PJSW, RMOV, RMOF, PRES"}}
But when I am trying
hotelCode.roomCodes , its Undefined.
Please help on this. Is it possible to do with javaScript
When you pull them out of the URL, the params are a string, they're not a javascript object.
Use something like this (in addition to what you have there)
var params = getQueryParameter('hotelinfo');
var hotelCode = JSON.parse(params);
Then hotelCode will actually contain a proper, walkable javascript object.

Categories

Resources