ช่วยทีครับ ไม่เข้าใจเลยครับ

เริ่มโดย teerapon, 06 มกราคม 2010, 22:02:38

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

teerapon

อ้างถึง
<?


$CONFIG{'hostname'} = 'localhost';
$CONFIG{'user'} = 'root';
$CONFIG{'password'} = '1234';
$CONFIG{'db'} = 'dataapi';


# WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING
#
# This script will attempt to create the database specified in $CONFIG{'db'}
# and a table called 'geo' in that database.
#
# WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING




$DBH = DB_Connect();

// Make sure the table exists
assertTable();

// define vars
$desc = '';
$lat = '';
$lon = '';

// read POST variables if present
foreach ($_POST as $name => $value) {
   $$name = $value;
}


// If post variables desc,lat and long are not empty then we're inserting
if ($desc &&  $lat &&  $lon) {
   if (is_numeric($lat) && is_numeric($lon) && is_string($desc)) {

      if ($lat < -85 || $lat > 85 || $lon < -180 || $lon > 180) {
         print "You've entered invalid values";
         exit;
      }

      $desc = addslashes(substr($desc,0,200));
      $sql = "insert into geoPoints values ( null , $lat, $lon, '$desc' )";
      $result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
      print "Point inserted<br><a href="{$_SERVER{'PHP_SELF'}}">Back to the map</a>n";
      exit;
   }
}


// Get the javascript defining the points after inserting.
$jsPointsArray = getPointsJS();



$pageHTML = <<<EOH

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Maps JavaScript API - PHP/DB Example</title>

   
//<script src="/key.js"></script> //¤ÅéÒ¡Òà include µÑÇ API Key ¨Ò¡ä¿Åì·ÕèÊÃéÒ§á¡äÇé ËÃ×ÍãÊèŧä»àÅÂẺºÃ÷Ѵ´éÒ¹ÅèÒ§¡çä´é
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAn6A4smCQuAu8CXVwR9hA2BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRIrVLREzSNq_ahG69m7OjycIH2zA"
type="text/javascript"></script>

<script type="text/javascript">
var mArray = Array();
var map;
var centerPoint = new GLatLng(13.897514,100.211771);

function load() {
   doLoad();
   $jsPointsArray
   addMarkers();
}

function doLoad() {
   if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("map"));
      map.setCenter(centerPoint, 15);
      map.addControl(new GScaleControl());
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      GEvent.addListener(map, 'click', mapClick);

   }
}

function addMarkers() {
   if (mArray.length) {
      var bounds = new GLatLngBounds();
      for (n=0 ; n < mArray.length ; n   ) {
         var mData = mArray[n].split(';');
         var point = new GLatLng(mData[0],mData[1]);
         bounds.extend(point);
         var marker = createMarker(point, mData[2]);
         map.addOverlay(marker);
      }
      map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
   }
}

function createMarker(point, title) {
   var marker = new GMarker(point,{title:title});
   GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml('<div style="width:250px;">'   title   '<hr>Lat: '   point.y   '<br>Lon: '   point.x   '</div>');
   });
   return marker;
}

function mapClick(marker, point) {
   if (!marker) {
      oLat = document.getElementById("lat");
      oLat.value = point.y;
      oLon = document.getElementById("lon");
      oLon.value = point.x;
      oDesc = document.getElementById("desc");
      oDesc.value = 'New point';


   }
}



</script>
</head>


<body onload="load()" onunload="GUnload()">

<div id="msg" style="width: 680px; border: 1px solid gray;font: bold 12px verdana;padding:3px;margin:10px;">
Note: Markers from all different visitors are going into the same database and are displayed together.<br>
They could be separated, but I chose to keep it simple. I'll empty the databse once in a while.
</div>

<div id="map" style="width: 700px; height: 500px"></div>


<div id="formDiv">
<table cellspacing="0" cellpadding="2">
<form method="POST">
   <tr>
      <td colspan="2" align="center">Add a marker</td>
   </tr>
   <tr>
      <td>Description</td>
      <td><input id="desc" name="desc"> Example: 'My marker</td>
   </tr>
   <tr>
      <td>Latitude</td>
      <td><input id="lat" name="lat"> Example: 40.0</td>
   </tr>
   <tr>
      <td>Longitude</td>
      <td><input id="lon" name="lon"> Example: -101.5</td>
   </tr>
   <tr>
      <td colspan="2" align="center"><input type="submit" value="Add Point"></td>
   </tr>
   <tr>
      <td colspan="2" align="center"><a href="/gm_markers_from_db.php.txt">View PHP source</a></td>
   </tr>
</form>
</table>
</div>




</body>

</html>



EOH;


print $pageHTML;


print DoQueriy('Table contents',"select * from geoPoints order by id");



///////////////////////////// Functions ///////////////////////////////////////

function getPointsJS() {
   global $DBH;
   $sql = "select * from geoPoints";
   $result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
   $nRows = mysql_num_rows($result);

   $javaScript = '';
   if ($nRows) {
      while ($row = mysql_fetch_assoc($result)) {
         $row{'description'} = addslashes($row{'description'});
         $row{'description'} = str_replace(';',',',$row{'description'});
         $javaScript .= "mArray.push('{$row{'lat'}};{$row{'lon'}};{$row{'description'}}')n";
      }
      
      print "Selected $nRows rowsn";
   }
   else {
      print "No points found in databasen";
   }
   return $javaScript;
}




function assertTable() {
   global $DBH;
   // Create table, if it does not already exist
   $createTableSQL = <<<EOS
   CREATE TABLE IF NOT EXISTS geoPoints (
     id int(11) NOT NULL auto_increment,
     lat decimal(12,8) NOT NULL,
     lon decimal(12,8) NOT NULL,
     description varchar(255) NOT NULL,
     PRIMARY KEY (id)
   ) TYPE=MyISAM;
EOS;

   $sql = $createTableSQL;
   $result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
}


function DBError($sql){
   print "Error: n" . mysql_error() . "n";
   print "<hr>n";
   print "$sqln";
   print "<hr>n";
   exit;
}



function DB_Connect() {
   global $CONFIG;
   $DBH = mysql_connect($CONFIG{'hostname'}, $CONFIG{'user'}, $CONFIG{'password'}) or DBError("LINE: " .__LINE__. " Connect");;

   $sql = "create database IF NOT EXISTS {$CONFIG{'db'}}";
   $result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
   
   mysql_select_db($CONFIG{'db'}, $DBH) or DBError("LINE: " .__LINE__. " Select DB");;
   return $DBH;
}



function DoQueriy($title,$sql){
   global $DBH;
   $HTML = '';

   $result = mysql_query($sql,$DBH) or DBError($sql);
   $colCount = mysql_num_fields($result);
   $rowCount = mysql_num_rows($result);

   $HTML .= "<table cellspacing="0" cellpadding="0" border>n";
   $HTML .= "<tr>n";
   $HTML .= "   <td colspan="$colCount" style="padding:3px;font-weight:bold;text-align:center;">n";
   $HTML .= "   $titlen";
   $HTML .= "   </td>n";
   $HTML .= "</tr>n";

   if ($rowCount) {
      if ($row = mysql_fetch_assoc($result)) {
         $HTML .= "<tr>n";
         foreach ($row as $name => $value) {
            $HTML .= "   <td style="padding:3px;">n";
            $HTML .=      $name;
            $HTML .= "   </td>n";
         }      
         $HTML .= "</tr>n";
      }
      
      mysql_data_seek($result,0);
      
      while ($row = mysql_fetch_assoc($result)) {
         $HTML .= "<tr>n";
         foreach ($row as $name => $value) {
            $HTML .= "   <td style="padding:3px;">n";
            $HTML .=      $value;
            $HTML .= "   </td>n";
         }      
         $HTML .= "</tr>n";
      }
   }
   else {
      $HTML .= "<tr>n";
      $HTML .= "   <td colspan="$colCount" style="padding:3px;font-weight:bold;text-align:center;">n";
      $HTML .= "   Emptyn";
      $HTML .= "   </td>n";
      $HTML .= "</tr>n";
   }
   
   $HTML .= "</table>n";
   $HTML .= "<br>n";
   return $HTML;

}


?>
นั่งแก้มาหลายวันแล้วครับ
ตั่งแต่ติดต่อฐานข้อมูลก็งง แล้วครับ

(O_o) นอทซ่าาO

หง่ะเปิดมางงเลย นึกว่าตัวเองมาตั้งกระทู้ รูป avata เดียวกันเลย  :wanwan004:

akeNAVY

โอ้ว.. :wanwan004:

รอท่านด้านล่างครับ

\/
\/
\/

บริการเพิ่มคะแนนเว็บไซต์ DA , DR , บริการ Backlink คุณภาพ----> http://chaiyobacklink.com , Line@ : @chaiyobacklink

galaxy

ผมเห็น Avatar ซ้ำๆกัน 2-3 คน และ

พาสับสน  :wanwan023: :wanwan023: :wanwan023:
รับทำหนังสือพอคเก็ตบุ๊คส ขายบนซีเอ็ด B2S ร้านหนังสือชั้นนำทั่วไป
ขาย Ebook สอนสุดยอดเคล็ดลับ(ที่คนทำหนังสือไม่เคยบอกคุณ)
แต่ผมจะสอนให้รวยด้วยการทำหนังสือขายบนซีเอ็ด  Ebook สอนเคล็ดลับ ราคา เพียง 5,000 ฿
(หนังสือผมวางขายอยู่บนซีเอ็ดกว่า 10 เล่ม) PM

ขายบัญชี Adsense อายุ 4 ปี 10,000 บาท มีเงินค้างอยู่ 15$  เหลือ 1 บช. **หมดแล้ว

SekRanger

งงอะไรล่ะครับ ไม่มีคำถาม ไม่มีคำบอกเล่า มีแต่คำว่างง


ผมอยากช่วยครับ แต่พูดตรงๆ ว่างงเหมือนกันครับ :-[

ซาเล้ง

อ้างถึงจาก: galaxy ใน 06 มกราคม 2010, 22:40:02
ผมเห็น Avatar ซ้ำๆกัน 2-3 คน และ

พาสับสน  :wanwan023: :wanwan023: :wanwan023:

ส่วนมากจะสับสน Panda Banned !
หยุดทุกอย่าง....

Kyon

ไม่เข้าใจบรรทัดไหนถามครับ แบบนี้ชวนหดหู่ ไล่บอกทีละบรรทัดก็... :P


utalert

ไม่เข้าใจเหมือนกัน ว่าถามอะไร

ploiro

นั่นสิครับ งงตรงไหน ก็อธิบายในส่วนที่ งงมาเลยครับป๋ม

เพื่อนๆพี่ๆ ที่นี่ เก่งๆกันทุกคนและพร้อมช่วยเหลืออยู่แล้วครับ
[direct=http://www.buyiphonetoday.com/]buy iphone[/direct]

[direct=http://www.sorndesign.com]สอนออกแบบ[/direct]
[direct=http://www.trendmestyle.com]แฟชั่นวัยรุ่น แฟชั่นอินเทรนด์ เสื้อผ้าวัยรุ่น เสื้อผ้าแฟชั่น [/direct]

[direct=http://www.outdoormistingfan.org]outdoor misting fan[/direct]

teerapon

นั้นเดียวผมมาถามใหม่ละกัน แต่งงหลายจุด มากากจนเกือบทั้งหมดเพราะไม่เคยเห็นแบบนี้อะครับ

Rapid-Developer

ผมตาลายหรือว่าเดี๋ยวนี้เขาเขียนกันแบบนี้แล้วหรอครับ ใช้ { } แทน [] กันแล้ว


$CONFIG{'hostname'} = 'localhost';
$CONFIG{'user'} = 'root';
$CONFIG{'password'} = '1234';
$CONFIG{'db'} = 'dataapi';


เขาไม่ได้ใช้ แบบนี้แล้วหรอครับ

$CONFIG['hostname'] = 'localhost';
$CONFIG['user'] = 'root';
$CONFIG['password'] = '1234';
$CONFIG['db'] = 'dataapi';


ผมดูใน code มีหลายจุดเลยสงสัยนะครับ เราไม่ได้ติดตาม PHP นานไปหรือเปล่าเนี่ย
--

Rapid-Developer

อย่างการ  Fetch Array ออกมาทำไมถึงใช้ { } แทน [ ] หรือครับ


while ($row = mysql_fetch_assoc($result)) {
         $row{'description'} = addslashes($row{'description'});
         $row{'description'} = str_replace(';',',',$row{'description'});
         $javaScript .= "mArray.push('{$row{'lat'}};{$row{'lon'}};{$row{'description'}}')n";
      }
--

teerapon

อ้างถึงจาก: Rapid-Developer ใน 06 มกราคม 2010, 23:50:30
อย่างการ  Fetch Array ออกมาทำไมถึงใช้ { } แทน [ ] หรือครับ


while ($row = mysql_fetch_assoc($result)) {
         $row{'description'} = addslashes($row{'description'});
         $row{'description'} = str_replace(';',',',$row{'description'});
         $javaScript .= "mArray.push('{$row{'lat'}};{$row{'lon'}};{$row{'description'}}')n";
      }

code ของพวก ฝรั่งครับ ซื้อ สคิ๊ปมาครับ มีคนซื้อมาครับผมขอเขามาครับ


Bes


[direct=https://client.hostsevenplus.com/aff.php?aff=396]✔ แนะนำ Hosting และ VPS ราคาเริ่มต้น 277 บาทฟรี! SSL ซัพพอทคุยง่าย[/direct]

[direct=https://www.bitkub.com/signup?ref=512782]✔ ซื้อบิทคอยที่ Bitkub (ได้รับการรับรองจาก กลต.)[/direct]