I have my jquery code which connects to getdata.php
. Here the val
is dynamic value and the function is called every time an option is selected from dropdown.
function getMoleculeData(val){
var molval=val;
var url = 'getmoldata.php';
$.ajax({
url: url,
data: 'molval='+molval,
method:'POST',
success: function(moldata) {
alert(moldata);
}
});
}
My getdata.php
code goes here
<?php
$molval = $_POST['molval']; // consider $_POST['molval']=ABC
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname= "userdata";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die ();
$query = "SELECT cm_id, CORP_RANK, CORP_MKT_SHARE, COMBINED_MOLECULE FROM PRODUCT_UNIVERSE_D WHERE COMBINED_MOLECULE ="."'$molval'";
$result = mysql_query($query) or die(mysql_error());
$i = 1;
$array = array();
while($row = mysql_fetch_array($result) {
$array[] = $row;
echo $row['CORP_RANK']; // etc
}
?>
Here is my table PRODUCT_UNIVERSE_D
cmid | CORP_RANK | CORP_MKT_SHARE | COMBINED_MOLECULE | DATE
1 | 10 | 30 | ABC | 01-04-2013
2 | 5 | 50 | ABC | 03-06-2013
3 | 8 | 40 | ABC | 23-09-2013
4 | 3 | 10 | XYZ | 05-01-2014
when I select ABC in dropdown, the same value is given in where clause and I am able to fetch the result. FOr the above code written in getdata.php
the output that I got is 1058
i.e the values of CORP_RANK where COMBINED_MOLECULE = 'ABC'. But the requirement is I have to get the result in the form of [10,5,8]
. How do I get the result in this array format and also how to fetch all the columns separately like $row['CORP_MKT_SHARE'] = [10,50,40]
and display them separately in success function of index.php
as
[10,5,8] and [10,50,40] for furthur use
Please help me out, as I am not perfect in fundamentals of arrays I am unable to get the result. Thanks in advance