...

View Full Version : How do I insert code into code



tonto
01-16-2010, 07:18 PM
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";

masterofollies
01-16-2010, 07:45 PM
What kind of error does it give you? also please use PHP code tags.


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";

tonto
01-16-2010, 09:34 PM
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.

tonto
01-17-2010, 08:12 PM
Anyone?

Dormilich
01-17-2010, 08:30 PM
does PHP run at all?

tonto
01-17-2010, 08:43 PM
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 :-(

Dormilich
01-17-2010, 08:45 PM
usually you put that in your top level script, so that it renders in the appropriate place.

tonto
01-17-2010, 08:49 PM
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);

Zoic
01-17-2010, 08:53 PM
You could do something like the following to get what your wanting.


$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. :)

tonto
01-17-2010, 09:02 PM
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 :-)))))

Zoic
01-17-2010, 09:08 PM
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.

tonto
01-17-2010, 09:12 PM
:-) I will come back and let you know how I get on!

Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum