PHP 板


LINE

看板 PHP  RSS
前几天才开始学写网页的所以观念不是很好,想来这边问一下 目标功能: 这是模拟一个使用者介面,用来达到远端控制遥控车的功能,网页上会有连续图片 看到遥控车目前看到的图片,而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







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP