How to call function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nma
    New Member
    • Aug 2007
    • 93

    How to call function

    Hi

    I have a function call getMovieLength. How do I call the function so that I can calculate the $cellwidth variable in the php code below. It shows error message like below
    "Notice: Use of undefined constant movieLength - assumed 'movieLength' in C:\htdocs\..\MB 2search.php on line 779
    Warning: Division by zero in C:\htdocs\..\MB 2search.php on line 784"


    [HTML]
    $movie = $db->get_row("selec t * from Movie where movieID='" . $_GET['movieID'] . "'");
    ....
    ....

    function getMovieLength( lengthString) {
    times = lengthString.sp lit(':');
    return (((parseInt(tim es[0]) * 60) + parseInt(times[1])) * 60) + parseInt(times[2]);
    }

    ...
    ...
    var movieLength = getMovieLength( "<?php echo $movie->duration?>") ;
    ...
    ...
    [/HTML]

    [PHP]
    <?php

    $allEvents = $db->get_results("S ELECT * FROM EventsShotsStar tAndStopFrames where movieID='" . $_GET['movieID'] . "' and eventCategory = 'Dialogue'");
    $prevTime = 0;
    $movieLengthTim eline = (movieLength * 30);

    foreach($allEve nts as $timeline)
    {
    $frameDuration = ($timeline->shotStartFrame ) - $prevTime;
    $cellwidth = round(($frameDu ration * 650)/ $movieLengthTim eline);//round here
    ?>

    <td width="<?php echo ($cellwidth); ?>" height="17" bgcolor=black></td>

    <?php
    $frameDuration = ($timeline->shotStopFram e) - ($timeline->shotStartFrame );
    $cellwidth = round(($frameDu ration * 650)/ $movieLengthTim eline);//round here

    ?>

    <td width="<?php echo ($cellwidth); ?>" height="17" bgcolor=green></td>
    <?php
    $prevTime = ($timeline->shotStopFrame) ;
    }
    ?>
    [/PHP]
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    PHP is assuming that movieLength is a constant because it is not a variable
    [PHP]$movieLengthTim eline = (movieLength * 30);[/PHP] What is it meant to be?

    Comment

    • nma
      New Member
      • Aug 2007
      • 93

      #3
      Hi

      It is actually calling a javascripts function into a php code..but I am not sure how to write it

      Thanks

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        It is not possible to call Javascript functions in your PHP code, or PHP functions in Javascript code.
        (Unless you use AJAX, but that's a whole other topic)

        This is because the Javascript code is execute on the client's browsers (client-side) while the PHP code is executed on the server (server-side) before the code is sent to the browser.

        The only way to have PHP call a Javascript function is to print the function call as Javascript code to the browser, but it can not directly interact with the Javascript code.

        Comment

        • Amzul
          New Member
          • Oct 2007
          • 130

          #5
          Code:
          var movieLength = getMovieLength("<?php echo $movie->duration?>");
          [CODE=php]$movieLengthTim eline = (movieLength * 30);[/CODE]
          u cant, (i am sure 99.9999% server / client)
          its a js var, data from php. so just try do:

          [CODE=php]$movieLengthTim eline = ($movie->duration * 30); [/CODE] if its possible

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by Amzul
            Code:
            var movieLength = getMovieLength("<?php echo $movie->duration?>");
            [CODE=php]$movieLengthTim eline = (movieLength * 30);[/CODE]
            u cant, (i am sure 99.9999% server / client)
            its a js var, data from php. so just try do:

            [CODE=php]$movieLengthTim eline = ($movie->duration * 30); [/CODE] if its possible
            That won't work, as the PHP $movie->duration variable is supposed to be run through the Javascript function and the result returned into PHP via the Javascript variable.

            The easiest solution to this problem is to re-write the Javascript function as a PHP function.

            Comment

            • nma
              New Member
              • Aug 2007
              • 93

              #7
              Hi All

              I solve the problem...I write the functions again in php and put before the running lines code inside the php and it works

              Is it ok if i put that php functions anywhere in php codes ?

              Thanks

              Comment

              Working...