Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Thanked 0 Times in 0 Posts

    calling php from javascript

    Hello, I'm calling a php function from javascript to fill a javascript array. This sample code doesn't cause errors in php or javascript but just doesn't work. The goal here will be to return a row at a time in comma delimited format much like the mysql_fetch_array function in php. I will also post in the php forum but being new to both I am posting here also. I appreciate any help.

    This is an example of the php function:

    function PopulateRecsArray() {
    global $recs; //a global array declared elsewhere
    static $count;
    if ($count == sizeof($recs)) {
    $count = -1;
    return false;
    } else {
    $count =+ 1;
    for ($i = 0; $i < sizeof($recs); $i++) {
    for ($j = 0; $j < sizeof($recs); $j++) {
    $returnstr .= "\"{$recs[$count][$j]}\"";
    return $returnstr;

    This is an example of the calling javascript function:

    function FillRecsArray() {
    var row, rowcount = 0, colcount = 0;
    while (row = PopulateRecsArray()) {
    Recs[rowcount] = new Array();
    Recs[rowcount][colcount] = row; //this is for testing just to get return value
    count =+ 1;

  2. #2
    Senior Coder
    Join Date
    Jul 2004
    New Zealand
    Thanked 2 Times in 2 Posts
    You can not call a PHP function from Javascript like that.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts