Hello, I'm trying to include a php code into my simple HTML and i'm not having any luck. Its a simple table of two cell's the first cell is a simple html string, the second one is the problematic one, i need it to be an int value that increses by 1 evry second. I know php has some tags that help controll the time flow like "int sleep(int)" but i'm too new to php to even know how to include a simple php code that would do this and print the value in the second cell evry time i refresh my page. the HTML part looks somthing like this. <body> <table width="400"> <td>String</td> <td>Here is where the int value should display</td> </body> HTML: And my PHP code is somthing like this but it most likely isn't working at all cause i never done this be4! <?php $a=1; while(true){ sleep(1); $a=$a+1; echo $a; } ?> PHP: Now i dont know wether im suposed to put this code directly into the HTML tag that declares my cell or i should somehow let HTML compiler know that he has to compile some PHP code as well as HTML Many of u mighit find many of my words stupid and for that i apologise but that is the reason im asking for help I thank evry1 in advance.
Hello, Just put your php code inside your TD tag. <body> <table width="400"> <td>String</td> <td><?php $a=1; while(true){ sleep(1); $a=$a+1; echo $a; } ?></td> </body> HTML: This should work fine ps: your main file must have the extension .php Best Regards, Francisco
Well i did what u suggested but it didnt work. My main Index.html is composed out of 2 html documents each in its own frame. so what i did is edit that html page that is suposed to show the table to what you suggested and i changed the extention as well. What i got when i opened the page is a msgbox asking me if i want do download the php , and the table html was not displayed at all. if i leave the extention .html it simply dosent work. If i change Index.html to index.php it asks does the same msgbox that asks me to download the .php doc additional question, is the php code i wrote actualy doing what it suposed to do? ty very much for the help so far
Make sure you're saving your files with the .php extension instead of the .html extension (i.e. Index.php, not index.html). Otherwise your PHP will just appear as text. You can put HTML into a PHP file, but you can't put PHP into an HTML file
So what ur saying is that all my web page files should be with extention .php? and in them the code is a bit HTML and a bit PHP?
Tnx for the help i got it to work now But it isnt doing what i want it to do.. When i refresh my page the page is white and dosent appear until the php code is finished calculating my variable $a after a few seconds it prints an enormus number and an error that probably means i passed well ovee the line of an normal integer number.. So i figured what it does is keeps adding 1 to varable $a until it brakes cause the number gets to big... Now what i realy wanted it to do is to add 1 to varable $a every second.. but when i refresh my page i want it to show me the current $a... I mighit have to use a database for this and i got it installed but again i never had anything done in SQL so i froze one again ! If there is a chance i can do that with no database and its fairly simple please do ur best to help me Otherwise i will get on reading guides obout SQL righit away ! info: Im running an apacahe server on Windows the client running is WAMPSERVER Cheers and thanks to all of you for helping so far
That's because you've got yourself a big ol' infinite loop there my friend while(true){ sleep(1); $a=$a+1; echo '<td>',$a,'</td>'; } Code (markup): Basically, what you're saying there is "While this statement is true, keep adding a+1" Unfortunately, your statement is always going to be true. And there's no need whatsoever for "sleep" Try while($a < 30){ $a=$a+1; echo '<td>',$a,'</td>'; } Code (markup): Meaning - "While the variable a contains a number less than 30, keep going. Otherwise, stop"
Oh, and also - There's nothing wrong with mixing HTML and PHP in the same file - there's no penalty incurred in the code execution