Prashanth Prashanth - 1 year ago 62
Javascript Question

How to display the querying 'DB' for get-variable with multiple values?

I am having a problem while displaying the value in the textbox.

I have check boxes that represent for applying job. When a user checks multiple check boxes and clicks the apply button, the

of the check box value is separated with
and send to
file using ajax:


and the script is

$('.job-apply').on('click', function(){
var selected = $('input[name="job[]"]:checked').map(function(i,e){return;}).get();
var res = selected.join(",");
url: 'php/applyView.php?id='+res,
dataType: 'json',
success: function(data){
if(data.length > 0)
var tmp = data[0];
window.location.href = "apply.php";

file is:

require "dbconnect.php";
$id = $_REQUEST['id'];

$query = mysqli_query($conn, "SELECT `job_title` FROM `job` WHERE `job_id` IN ($id)");

$results = array();

while($row = mysqli_fetch_array($query))
$results[] = array(
'apply_title' => $row['job_title'],

$json = json_encode($results);

echo $json;

Output for the JSON Value is:

[{"apply_title":"Web developer"},{"apply_title":"Software Engineer"},{"apply_title":"Web developer"}]

file is:

<form role="form" class="post-resume-form">
<div class="form-group">
<label for="job_title">Job Title</label>
<input type="Text" class="form-control input" id="apply-title" value="" />

Now the problem is to display only the value of the
with separated by
is it possible.

In the form text box it has to be like this:

"Web Developer","Software Engineer","Web Developer"

Help me out guys!!

Answer Source

If I'm not mistaken, you want to take only the apply title, separated by commas. Instead of the echo(or beneath it) you can add this code:

$allTitles = "";
foreach($results as $applytitle){
   $allTitles = $allTitles . $applytitle["apply_title"] . ",";
echo $allTitles;

This should output Web Developer,Software Engineer,Web Developer,. The last comma(in the output) can be removed with a substring method.

NOTE: I haven't tested this, so it may not work! If you get an error, contact me

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download