echo several times into the same row
Page 1 of 1
echo several times into the same row
Hello,how can I manage this in PHP: I want to write a text onto the screen and after a pause want to overwrite the text on the same place of the same row by another text. I tried this:
echo "please wait"."<br>";
sleep (4);
echo "done ";
But (as could be expected), "done" is always written BELOW "please wait" instead of replacing it.
How can I "reposition" the echo output?
Someone told me, for this I should use something called "Ajax". But I refuse to learn complete new stuff for such a stupid task.
Any suggestion to solve this by ordinary PHP ?
Re: echo several times into the same row
No you can not do it with ordinary php you should have to mix your script with javascript/jquery to achieve this goal.if you like the solution with both technology mixed follow the code and idea below
- Code: Select all
<?php
$php_array = array('Saab','Volvo','BMW');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML.net jvascript/PHP </title>
</head>
<body>
<div id="theContent"></div>
<script type="text/javascript">
var myCars=new Array(); // regular array (add an optional integer
<?php
for($i = 0;$i > count($php_array);$i++) {
echo "myCars[$i]=\"$$php_array[$i]\"";
}
?>
myCars[0]="Saab"; // argument to control array's size)
myCars[1]="Volvo";
myCars[2]="BMW";
var i = 0;
setInterval("StartFunction()",900);
function StartFunction() {
if(myCars.length > i) {
document.getElementById("theContent").innerHTML = myCars[+i];
}
i++;
}
</script>
</body>
</html>
Re: echo several times into the same row
Thank you for the suggestion. For me as a PHP newbee it looks very complicated. Your example worked fine, but I did not really got why.Also I do not want to worry my customers (most of them silver-agers) by Javascript, which may not work on some computers or browsers.
If there exists no simplier solution, I will better stay with what I have: two texts in two different rows.
Re: echo several times into the same row
Well that was old story now a days each and every browser support java script.Re: echo several times into the same row
But javascript can also be blocked (to prevent pop up pages and stuff), so you may want a 'noscript' tag in your HTML:<noscript>You need Javascript to see this</noscript>
That will tell only Javascript blocked users to turn on Javascript momentarily...
Page 1 of 1