I have in table columns name and rc. I retrieve values by select in php by js code info array.
I want to display this values in html table with other values by javascript.
My question: Whats way to join values name and rc in js? I need to join values and split them by CRLF and display them in one tag <td>.But in js.

$sql = "select rc, meno from jqcalendar where  sala_typ='$sala_typ' and left(StartTime,10)  ='$datumvykonu'";
$handle = mysql_query($sql);

$retArray = array();
while ($row = mysql_fetch_row($handle)) {
  $retArray[] = $row;
}
$data = json_encode($retArray);
$ret = "{data:" . $data .",\n";
$ret .= "recordType : 'array'}";
echo $ret;

-- other php page ---

<script type="text/javascript" >
var grid_demo_id = "myGrid1" ;

var dsOption=
{

    fields :
    [
        {name : 'rc'  },
        {name : 'meno'  }
    ],
    recordType : 'array'
}


var colsOption = 
[
    {id: 'rc' , header: "Rod.cislo" , width :80  },
    {id: 'meno' , header: "Meno" , width :100  }
];
</script>

Thanks.

Value split by CRLF:

var str=query_result;
var strArray = str.split("\r\n");

strArray will be an array of length strArray.length
Elements can be accessed by the [] selector (e.g., strArray[0], strArray[1]).

Also, you may have to modify \r\n delimiters according to the operating system you are working on.

To join values together, you can use the + string
operator. Ex:

finished_string = string1 + "some-delimiter" + string2 + "some-delimiter"
              + string3 + "some-delimiter" + string4;

where "some-delimiter" could be &nbsp; or other character.

To print out the values in a <td> tag. You will have to call a JavaScript function which you define from within your HTML page.

For example:

<script language="JavaScript">
function writeColumn()
{
  // use global variables to write the output.
  document.write("<td>");
  document.write(finished_string);
  document.write("</td>");
} 
</script>

To call this from HTML, you would have something like:

   <script>writeColumn();</script>

I doubt that this above line would actually be the code you use, but it is intended to give you the idea.

Others posters here can explain more if you are still having trouble.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.