I have data coming from mysql and the need to show in the drop down list. The code is below.
This data value will come from mysql. So I need to show all these values in the dropdown list. Looking for a solution.
var data = "user data1, user data2, user data3, user data4/ user data6, user data7, user data8/ user data5, user data9";
function studentPopulate(){
$.each(newTotalData, function(key, value) {
$('#sList')
.append($("<option></option>")
.attr("value",key)
.text(value));
});
}
var totalData = [];
var data_array = [];
var arrayVal = [];
var newTotalData = new Array();
function studentInfo(){
$.getJSON("checkData.php", {section_id:section_id, uID: uID}, function(data) {
$.each(data, function(i, user) {
var data = user.groupContent;
data_array = data.split('/').join(',');
totalData.push(data_array);
arrayVal = totalData;
newTotalData = arrayVal[0].split(',');
studentPopulate();
});
});
}
PHP code is here:
<?php
include 'connection.php';
$uID = $_GET["uID"];
$cid = $_GET["section_id"];
mysqli_select_db($con, "DB");
$Query="SELECT * from table WHERE uid='".$uID."' and section_id='".$cid."'";
$result = mysqli_query($con, $Query);
$totalRecords = mysqli_num_rows($result);
//echo $totalRecords;
if($totalRecords) {
while ($row = mysqli_fetch_array($result)) {
$returnData[]=array( //for Json data array
'userName' => $row['fullName'],
'groupContent' => $row['groupContent']
);
}
}
mysqli_close($con);
echo json_encode($returnData);
?>
Change of dropdown value. I need to find out the dropdown text inarray. Just updated my code. It seems like it can't find the value in array. Please help. It can find newTotalData but I need to find out the group(array) of that dropdown value.
$('#sList').change(function()
{
var str = $(this).find(":selected").text();
if($.inArray(str,data_array[0])>=0){alert(data_array[0])};
});
}
arrayValhave 3 different array in it , you can't split that