Login | Register | FAQ
Anonymous

echo several times into the same row

+ Post a reply

5 posts Page 1 of 1


echo several times into the same row

by Wieisses » Sat May 19, 2012 2:41 pm

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 ?
User avatar

Wieisses

  • Posts: 2
  • Joined: Sat May 19, 2012 2:16 pm

Re: echo several times into the same row

by XainPro » Sat May 19, 2012 7:30 pm

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>
User avatar

XainPro

  • Posts: 3567
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: echo several times into the same row

by Wieisses » Sun May 20, 2012 2:56 pm

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.
User avatar

Wieisses

  • Posts: 2
  • Joined: Sat May 19, 2012 2:16 pm

Re: echo several times into the same row

by XainPro » Mon May 21, 2012 5:41 am

Well that was old story now a days each and every browser support java script.
User avatar

XainPro

  • Posts: 3567
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: echo several times into the same row

by soccerwebsitemaker » Wed May 23, 2012 10:22 am

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...
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/


+ Post a reply

Page 1 of 1

?>