Sunday, August 26, 2018

GOOGLE MAP + 留言板概念

GOOGLE MAP + 留言板 概念

資料
流程圖
login.php
<script> function get_value() { cookie ={tmp="",tmp2="",tmp2="",tmp2="",tmp2="",tmp2="",rand_id=""} if(document.cookie.indexOf("rand_id=")==-1) var n = Math.floor(Math.random() * (10000 - 0 + 1)) + 1000; setCookie("rand_id",(n).toString()); } function myfocus() { document.getElementById('ok').focus(); } function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString(); } function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null; } </script> <html> <head> <title>用戶登錄</title> </head> <body onload='myfocus()'> <p>請輸入您的暱稱 </p><br> //// <form action="main.php" method="post" target="_self"> / <input type="text" id="ok" name="nick" cols="20"> <<<<<--------- <input type="submit" value="開始聊天" onClick="get_value()">- </body></html>
main.php
<?php $value = $_POST['nick']; setcookie("nick",$value) ; ?> http://www.w3school.com.cn/php/func_http_setcookie.asp <html> <title>jack chat</title> <frameset rows="85%,*"> <frame src=" cdisplay.php" name="chatdisplay"> <frame src="speak.php" name="speak"> </frameset> </html>
speak.php
帳號:gmph15973@gmail.com
密碼:94879487
<script> 
function myfocus() 
{ document.getElementById('ok').focus(); } 
function EvalSound(soundobj) { 

var thissound = document.getElementById(soundobj); 
thissound.Play(); }


function DHTMLSound(surl) {
    document.getElementById("dummyspan").innerHTML =
      "<embed src='" + surl + "' hidden=true autostart=true loop=false>";
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]);
    else
        return null;
} 
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null)
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
} 
function CheckForm()

{

  if(confirm("你確定要離開嗎?")==true)   
{
 delCookie("rand_id");
delCookie("pairid");
}
  else  

    return false;

}   
</script>
<?php $value =$_COOKIE['nick']; $words =$_POST['words']; If ($words) { $link_ID=mysql_connect("localhost","root","root"); mysql_query("SET NAMES utf8"); $db_selected = mysql_select_db("message", $link_ID); if (!$db_selected) die("開啟資料庫失敗"); $time = date("Y-m-d H:i:s"); $str="INSERT INTO message (time,name,text,Pair_ID) values ('$time','$value','$words','$pairid');" ; mysql_query($str,$link_ID); //送出發言到數據庫 mysql_close($link_ID); } if(!empty($_SERVER['HTTP_CLIENT_IP'])){ $myip = $_SERVER['HTTP_CLIENT_IP']; }else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $myip = $_SERVER['HTTP_X_FORWARDED_FOR']; }else{ $myip= $_SERVER['REMOTE_ADDR']; } ?>
cdisplay.php
<script> 

function get_value()
{if(document.cookie.indexOf("name=")==-1)
setCookie("name","1");
var username=parseInt(getCookie("name"));
//document.write( username);
//document.write(parseInt(bo1));
//document.write(getCookie("rand_id"));
if(parseInt(bo1)>username){
DHTMLSound('Ringing.mp3');

}
setCookie("name",bo1);
}

function set_pairid()
{setCookie("pairid",pairid);
}
function myfocus() 
{ document.getElementById('ok').focus(); } 
function EvalSound(soundobj) { 

var thissound = document.getElementById(soundobj); 
thissound.Play(); }


function DHTMLSound(surl) {
    document.getElementById("dummyspan").innerHTML =
      "<embed src='" + surl + "' hidden=true autostart=true loop=false>";
}
 function setCookie(name,value)
{
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
} 
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null)
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
} 
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]);
    else
        return null;
} 
</script>
?<html>
<head>
<title>顯示用戶發言</title>
<meta http-equiv="refresh" content="5;url=cdisplay.php">
<form action="cdisplay.php" method="get">
<span id=dummyspan></span>
<input type="hidden" name="h1" value="h1">
<meta charset="UTF-8">
</head>
<body>
<?php
$chtime2=1;
//延遲時間
@$value=$_COOKIE['nick'];
//抓cokies 給value
@$words=$_POST['words'];
$link_ID=mysql_connect("localhost","root","root");
        if (!$link_ID) die("建立資料連接失敗");
//鏈接Mysql伺服器 伺服器名為main,管理員名為root
mysql_query("SET NAMES utf8"); 

//數據庫編碼設定為utf8語系
$db_selected = mysql_select_db("message", $link_ID);
        if (!$db_selected) die("開啟資料庫失敗");
//選擇數據庫

$tmp=$_COOKIE["rand_id"];
$tmp2=$_COOKIE["pairid"];
echo $tmp; 
echo $tmp2;

$str="select * from online_user where Pair='0' and ing='0'";
$rows=mysql_num_rows(mysql_query($str,$link_ID));
//echo $rows;
if($rows/2>=1)
{
$str="UPDATE online_user SET ing='1' where Rand_ID='$tmp' and ing='0' and Pair='0' ";
$result=mysql_query($str,$link_ID); 
$str="select * from online_user where Rand_ID='$tmp' and Pair='0'";
$rows=mysql_num_rows(mysql_query($str,$link_ID));

if($rows==1)
{

$str="select * from online_user ";
$rows2=mysql_num_rows(mysql_query($str,$link_ID));
$str="select * from online_user number where Rand_ID='$tmp' and Pair_ID='0' ";
$result=mysql_query($str,$link_ID); 
list($my,$tmp2,$tmp3,$tmp4,$tmp5)=mysql_fetch_row($result);
$Rand_tmp=$tmp5;
while($Rand_tmp==$tmp5)
{
$Rand_tmp= rand(1,$rows2);
}
$str="UPDATE online_user SET ing='1' where number='$Rand_tmp' and ing='0' and Pair='0' ";
$result=mysql_query($str,$link_ID); 

$str="select * from online_user  where number='$Rand_tmp' and Pair_ID='0' ";
$result=mysql_query($str,$link_ID); 
list($other,$tmp2,$tmp3,$tmp4,$out)=mysql_fetch_row($result);
//echo $tmp1,$tmp2,$tmp3,$tmp4,$tmp5;
//echo $tmp5;
//echo $Rand_tmp;
$str="UPDATE online_user SET Pair_ID='$other', Pair='1',ing='0' where number='$tmp5' and ing='1'  ";
$result=mysql_query($str,$link_ID); 
echo "<script>var pairid='$other'</script>";
echo "<script>set_pairid()</script>";



$str="UPDATE online_user SET Pair_ID='$my', Pair='1',ing='0' where number='$Rand_tmp' and ing='1'";
$result=mysql_query($str,$link_ID); 
}

}

$tmp=$_COOKIE["rand_id"];
$str="select * from online_user  where Rand_ID='$tmp' and  Pair_ID='0'";
$rows=mysql_num_rows(mysql_query($str,$link_ID));
if($rows==1)
{$str="UPDATE online_user SET Pair_ID='0', Pair='0' , ing='0' where Rand_ID='$tmp' and  Pair_ID='0'";
$result=mysql_query($str,$link_ID); 
die("wait...");
}

$tmp=$_COOKIE["rand_id"];
$str="select * from online_user  where Pair_ID='$tmp'";
$rows=mysql_num_rows(mysql_query($str,$link_ID));
if($rows>1)
{$str="UPDATE online_user SET Pair_ID='0', Pair='0' , ing='0' where Rand_ID='$tmp' and  Pair_ID='0'";
$result=mysql_query($str,$link_ID); 
die("wait...");
}

$tmp=$_COOKIE["rand_id"];
$str="select * from online_user  where Rand_ID='$tmp' and  Pair_ID>0";
$rows=mysql_num_rows(mysql_query($str,$link_ID));
if($rows==1)
{
$str="select * from online_user  where Rand_ID='$tmp' and  Pair_ID>0";
$result=mysql_query($str,$link_ID); 
list($my,$tmp2,$tmp3,$tmp4,$tmp5)=mysql_fetch_row($result);


 //if (isset($_COOKIE["pairid"])) { echo "變數存在"; } else { echo "變數不存在"; }

echo "<script>var pairid='$tmp2'</script>";
echo "<script>set_pairid()</script>";
}
$tmp=$_COOKIE["rand_id"];
$tmp2=$_COOKIE["pairid"];

$str="select * from message  where Pair_ID='$tmp'or Pair_ID='$tmp2'  ORDER BY time ";
//依名稱排序name這欄位是時間
$result=mysql_query($str,$link_ID); 
//送出查詢
$rows=mysql_num_rows($result); 
//取得查詢結果的記錄筆數
//取得最后15筆發言,并顯示
@mysql_data_seek($resut,$rows-15); //移動記錄指針到前15筆記錄
echo "<script>var bo1='$rows'</script>";

if ($rows<15)
 $l=$rows;
 else
 $l=15; //記錄總數小于15,則最多為該記錄數
for ($i=1;$i<=$l;$i++ )
 {
list($name,$url,$body)=mysql_fetch_row($result);
echo $name; echo " ";echo $url; echo":" ; echo $body; echo "<BR>";
}

//清除庫中過時的數據
@mysql_data_seek($result,$rows-20); //移動記錄指針到前20筆記錄
list($limtime)=mysql_fetch_row($result);
$str="DELETE FROM message WHERE $chtime2<'$limtime' ;" ;
$result=mysql_query($str,$link_ID); //送出查詢字符串,庫中只留前20個記錄
mysql_close($link_ID);
echo "<script>get_value()</script>";
echo "<script>var bo2='$rows'</script>";

?>
</body>
/html>


**map.php**
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" /> <!--語系UTF-8-->
    </head>
    <body>
        <style>
            /*設定gmap_canvas顯示區(寬與高)*/
            #gmap_canvas{
                width:100%;
                height:30em;
            }
        </style>
        
        <!--地圖顯示區-->
        <div id="gmap_canvas"></div>

        <?php
        //-----Google map value Start-----
        $set_address="台中市西區公益路68號"; //填寫所要的地址,Example地址為勤美綠園道
        $data_array = geocode($set_address);
        $latitude = $data_array[0];
        $longitude = $data_array[1];
        $data_address = $data_array[2];
        //-----Google map value End-----
        
        //-----function start-----
        function geocode($address){
            /*用來將字串編碼,在資料傳遞的時候,如果直接傳遞中文會出問題,所以在傳遞資料時,通常會使用urlencode先編碼之後再傳遞*/
            $address = urlencode($address);

            /*可參閱:(https://developers.google.com/maps/documentation/geocoding/intro)*/
            $url = "http://maps.google.com/maps/api/geocode/json?address={$address}&language=zh-TW";

            /*取得回傳的json值*/
            $response_json = file_get_contents($url);

            /*處理json轉為變數資料以便程式處理*/
            $response = json_decode($response_json, true);

            /*如果能夠進行地理編碼,則status會回傳OK*/ 
            if($response['status']='OK'){
                //取得需要的重要資訊
                $latitude_data = $response['results'][0]['geometry']['location']['lat']; //緯度
                $longitude_data = $response['results'][0]['geometry']['location']['lng']; //精度
                $data_address = $response['results'][0]['formatted_address'];

                if($latitude_data && $longitude_data && $data_address){

                    $data_array = array();            
                    
                    //一個或多個單元加入陣列末尾
                    array_push(
                        $data_array,
                        $latitude_data, //$data_array[0]
                        $longitude_data, //$data_array[1]
                        '<b>地址: </b> '.$data_address.'<br>test</br>' //$data_array[2]
                                        
                    );

                    return $data_array; //回傳$data_array

                }else{
                    return false;
                }

            }else{
                return false;
            }
        }
        //-----function end-----
        ?>
    </body>
</html>

<!-----google map Start----->
<!--可參閱:(https://developers.google.com/maps/documentation/javascript/3.exp/reference)-->
<script src="http://maps.google.com/maps/api/js?language=zh-TW"></script>
<script>
    function init_map() {
        /*地圖參數相關設定 Start*/
        var Options = {
            zoom: 14, /*縮放比例*/
            center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>) /*所查詢位置的經緯度位置*/
        };
        
        map = new google.maps.Map(document.getElementById("gmap_canvas"), Options);
        /*地圖參數相關設定 End*/
        
        /*自行設定圖標 Start*/
        var image = {
            url: 'https://google-developers.appspot.com/maps/documentation/javascript/examples/full/images/beachflag.png', /*自定圖標檔案位置或網址*/
            // This marker is 20 pixels wide by 32 pixels high.
            size: new google.maps.Size(20, 32), /*自定圖標大小*/
            // The origin for this image is (0, 0).
            origin: new google.maps.Point(0, 0),
            // The anchor for this image is the base of the flagpole at (0, 32).
            anchor: new google.maps.Point(0, 32)
          };
        
        marker = new google.maps.Marker({
            map: map,
            position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>), /*圖標經緯度位置*/
            icon: image
        });
        /*自行設定圖標 End*/
        
        /*所查詢位置詳細資料 Start*/
        infowindow = new google.maps.InfoWindow({
            content: "<?php echo $data_address; ?>"
        });
        
        infowindow.open(map, marker);
        /*所查詢位置詳細資料 End*/
    }
    
    /*
    事件偵聽器
    (可參閱:https://developers.google.com/maps/documentation/javascript/events)
    */
    google.maps.event.addDomListener(window, 'load', init_map);
</script>
mysql
新增資料
select
select * from online_user where Pair=’0’ and ing=’0’
1.select * from test1;
2.select * from test1 where test=’1’;
3.select test2 from test1 where test=’1’;
update
UPDATE test1 SET test=’555’ where test=’1’;
delete
DELETE FROM test WHERE  test=’555’;
** insert**
INSERT INTO test1 (test,test2) values(’123’,’130’);
UPDATE (要做三小) where (條件);
select  (要做三小) where (條件);
delete (要做三小) where (條件);
insert (要做四小) where (條件);
XAMPP
你們的網頁 :127.0.0.01/XXX.php
你的的資料庫:127.0.0.01/phpmyadmin.php
  • 127.0.0.01/phpmyadmin
ㄎㄎㄎ安卓新課程