作者tangent7787 (打刚甲憨吉)
看板PHP
标题[请益] 不换页连续写档and PHP传字串
时间Wed Sep 7 17:37:49 2011
前几天才开始学写网页的所以观念不是很好,想来这边问一下
目标功能:
这是模拟一个使用者介面,用来达到远端控制遥控车的功能,网页上会有连续图片
看到遥控车目前看到的图片,而button有 前 後 左 右 停 五个按钮来控制遥控车,
前後左右停五个按钮每按下一次就会写入log档中,而另外有一只C code的程式用来
读取这个log档来达到控制方向的功能
前提:尽量不使用sql(因为这是run在嵌入式开发板上跑的,再移植sqlite怕来不及)
问题:
1.网页上的按钮按下後档案只会写入一次,
Ex:按下button顺序:Stop,Front,Back,Left,Right,Stop,Stop,Stop...
照理说写入的log档应该也是Stop,Front,Back,Left,Right,Stop,Stop,Stop...
但档案却是Stop,Front,Back,Left,Right 就没了
不知道是不是因为没有换页的原因? 我看别人送跟收都是分成server与client
两个网页?可是我的网页介面不想要让使用者看起来像是有跳页的感觉
2.因为我不会传字串,所以现在code感觉很冗长,明明是一样的功能只是写入的字串
不一样,希望是把现在front,back,left,right,stop浓缩成WriteLog一个function
就好....因为只有差字串XD
先感谢大家看完我的问题Orz
在这里拜托神手求解.....
=================== source code =======================
<HTML>
<head>
<title>ThirdEye-System</title>
<?php
/*function WriteLog(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Front.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}*/
function front(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Front.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function back(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Back.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function left(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Left.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function right(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Right.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
function stop(){
$myFile = "Drive.log";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Stop.\n";
//$stringData = $_POST['direction'];
fwrite($fh, $stringData);
fclose($fh);
}
?>
</head>
<body>
<H1>Welcome to ThirdEye System</H1>
<canvas id="cvs" width="700" height="540">[No canvas support]</canvas>
<script>
var serverAddress = "snap.jpg";
var counter=0;
function drawPicCanvas(){
var ctx = document.getElementById('cvs').getContext('2d');
ctx.clearRect (0, 480, 300, 510);
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
//ctx.beginPath();
//ctx.moveTo(30,96);
//ctx.lineTo(70,66);
//ctx.lineTo(103,76);
//ctx.lineTo(170,15);
//ctx.stroke();
};
img.src= "snap.jpg?"+ new Date().getTime();
ctx.font = 'bold 30px sans-serif';
ctx.textBaseline = 'top';
ctx.strokeText('Image No.'+counter, 0, 480);
counter++;
setTimeout(drawPicCanvas,1000);
}
drawPicCanvas();
</script>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<! stop >
<div style="top :380px; left : 580px; position : absolute;"
id="StopButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php stop() ?>">
<font size=20 color="#0000FF">Stop</font>
</button>
</div>
<! go forward >
<div style="top :310px; left : 580px; position : absolute;"
id="FrontButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php front() ?>">
<font size=20 color="#0000FF">Front</font>
</button>
</div>
<! go back >
<div style="top :450px; left : 580px; position : absolute;"
id="BackButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php back() ?>">
<font size=20 color="#0000FF">Back</font>
</button>
</div>
<! turn left >
<div style="top :380px; left : 440px; position : absolute;"
id="LeftButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php left() ?>">
<font size=20 color="#0000FF">Left</font>
</button>
</div>
<! turn right >
<div style="top :380px; left : 720px; position : absolute;"
id="RightButton">
<button type="button"style="height: 70px; width: 140px"
onClick="<?php right() ?>">
<font size=20 color="#0000FF">Right</font>
</button>
</div>
</form>
</body>
</HTML>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.243.171.65
1F:推 eight0:呃 在浏览器按右键检视原始码大概就知道哪里不太对了 09/07 19:05
2F:推 characterlu:前几天才开始写 可以血这样喔 09/07 23:57
3F:→ tangent7787:喔我是参考很多code然後都在一起的XD 09/08 10:11
4F:→ tangent7787:一楼大大可以说详细点吗 谢谢 我不太会用QQ 09/08 10:29
5F:→ tangent7787:我这样call function好像根本是错得.. 09/08 10:57
6F:→ tangent7787:已解决,谢谢! 09/08 14:36