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

    How do I insert code into code

    Hi all, I am a php newbie and a bit stumped. I am trying to insert a time and date peice of code into a php script to modofy it but I cannot get ti to work.
    Please could someone give a pointer as to what is wrong here?

    Many thanks :-)

    Original code:

    database_querySelect($sqlResultCount,$rows);

    $resultCount = $rows[0]["resultcount"];

    $banner["h2"] = translate("&nbsp;<font color='#008000'><strong>search results-on CLOCK CODE HERE</strong></font>")."&nbsp;";

    if ($resultCount)
    {
    $resultFrom = ($offset+1);

    $resultTo = ($offset+$config_resultsPerPage);

    if ($resultTo > $resultCount) $resultTo = $resultCount;

    and this is the php clock code to go where it says CLOCK CODE HERE:

    echo date('l jS \of F Y \a\t ');
    putenv("TZ=Europe/London");
    echo date("h:i a")."\n";

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    What kind of error does it give you? also please use PHP code tags.

    PHP Code:
    database_querySelect($sqlResultCount,$rows);

    $resultCount $rows[0]["resultcount"];

    $banner["h2"] = translate("&nbsp;<font color='#008000'><strong>search results-on CLOCK CODE HERE</strong></font>")."&nbsp;";

    if (
    $resultCount)
    {
    $resultFrom = ($offset+1);

    $resultTo = ($offset+$config_resultsPerPage);

    if (
    $resultTo $resultCount$resultTo $resultCount;

    and 
    this is the php clock code to go where it says CLOCK CODE HERE:

    echo 
    date('l jS \of F Y \a\t ');
    putenv("TZ=Europe/London");
    echo 
    date("h:i a")."\n"
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry, there is no error displayed on the page it just doesn't display anything as if it isn't there.. By php tags do you mean the <?php-?> tags?

    Thanks.

  • #4
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Anyone?

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,216
    Thanks
    12
    Thanked 338 Times in 334 Posts

    Macintosh

    does PHP run at all?

  • #6
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hello, thanks for replying, the page works fine but the problem is I do not know how to place the clock code into the other php code so that it will display.. Although the page works the clock does not show in the browser :-(

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,216
    Thanks
    12
    Thanked 338 Times in 334 Posts
    usually you put that in your top level script, so that it renders in the appropriate place.

  • #8
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So should it work if I just insert it like this-as it doesn't appear to?

    database_querySelect($sqlResultCount,$rows);

    $resultCount = $rows[0]["resultcount"];

    $banner["h2"] = translate("&nbsp;<font color='#008000'><strong>search results-on <?php echo date('l jS \of F Y \a\t ');
    putenv("TZ=Europe/London");
    echo date("h:i a")."\n"; ?></strong></font>")."&nbsp;";

    if ($resultCount)
    {
    $resultFrom = ($offset+1);

    $resultTo = ($offset+$config_resultsPerPage);

  • #9
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    You could do something like the following to get what your wanting.

    PHP Code:
    $date1 date('l jS \of F Y \a\t ');
    putenv("TZ=Europe/London");
    $date2 date("h:i a")."\n"

    $banner["h2"] = translate("&nbsp;<font color='#008000'><strong>search results-on ".$date1.$date2."</strong></font>")."&nbsp;"
    Let me know if this worked or not.

  • #10
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Amazing, I cannot thank you enough, it worked perfectly straight away, I am going to try to learn more about php, I am familiar with javascript but php is new to me and seems a far better way of getting clever stuff into a page getting the server to do the work rather than the browser.

    Thanks again :-)))))

  • #11
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Not a problem at all!

    PHP is a really fun language and can do some amazing things. You're in for a treat if you ask me lol.

  • Users who have thanked Zoic for this post:

    tonto (01-17-2010)

  • #12
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    :-) I will come back and let you know how I get on!

    Thanks again.


  •  

    Tags for this Thread

    Posting Permissions

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