Advanced Search

Results 1 to 4 of 4

Thread: how to

  1. #1
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to

    how i can to define this code into a variable?

    PHP Code:
    srand ((double) microtime( )*1000000);
    $random_number rand( ); 
    where $random_number is a variable to call like this:

    <b>$random_number</b>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I don't understand you. "Define this code into a variable?" You mean you want to create a function? And the way you use that variable - short of a here-document - is never going to work. You want:
    Code:
    <b><?php echo($random_number); ?></b>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I need to create this code in a so called variable <module:randomnumber> for then to be able to integrate with javascript. regards

    example:

    HTML Code:
    <SCRIPT>ppreview('http://www.google.com','<module:randomnumber>')</SCRIPT> 
    <SCRIPT>potherfunctions('http://www.google.com','<module:randomnumber>', '')</SCRIPT>

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <SCRIPT>ppreview('http://www.google.com','<?php echo($random_number); ?>')</SCRIPT>
    <SCRIPT>potherfunctions('http://www.google.com','<?php echo($random_number); ?>', '')</SCRIPT>
    PHP and Javascript work at very different levels to one another, and the only way to pass a variable from PHP to Javascript is to echo it straight into the Javascript code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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