รบกวนพี่ๆช่วยบอกเกี่ยวกับการเพิ่มฟังก์ชันการค้นหาจากฐานข้อมูล
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา รบกวนพี่ๆช่วยบอกเกี่ยวกับการเพิ่มฟังก์ชันการค้นหาจากฐานข้อมูล
รบกวนพี่ๆช่วยบอกเกี่ยวกับการเพิ่มฟังก์ชันการค้นหาจากฐานข้อมูล
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | รบกวนพี่ๆช่วยบอกเกี่ยวกับการเพิ่มฟังก์ชันการค้นหาจากฐานข้อมูล <span lang= "th" class = "short_text" id= "result_box" ><span class = "hps" >ขอบคุณมาก </span></span> index.php <?php // connect to the database include "connect.php" ; ?> <html> <head> <title>Interactive Travel Map</title> <script type= "text/javascript" src= "jquery-1.4.2.min.js" ></script> <script type= "text/javascript" src= "jquery-ui-1.8rc3.custom.min.js" ></script> <link type= "text/css" href= "jquery-ui-1.8rc3.custom.css" rel= "stylesheet" /> <script> // checks if the user provided all the data for adding a new location function check() { if (document.getElementById( 'lat' ).value == "" || document.getElementById( 'long' ).value == "" || document.getElementById( 'address' ).value == "" ) { alert( "Click on the map to choose location!" ); return false; } if (document.getElementById( 'name' ).value == "" ) { alert( "Write a name for the new location!" ); return false; } if (document.getElementById( 'description' ).value == "" ) { alert( "Write a description for the new location!" ); return false; } if (document.getElementById( 'user_name' ).value == "" ) { alert( "Write your name!" ); return false; } if (document.getElementById( 'user_location' ).value == "" ) { alert( "Write your location!" ); return false; } if (document.getElementById( 'photo' ).value == "" ) { alert( "Choose a photo for the new location!" ); return false; } return true; } </script> <style> html { height: 100%; } body { background: #eeeeee; height: 100%; margin: 10; padding: 0; line-height: 150%; } * { font-size: 10pt; font-family: Tahoma, Verdana, sans-serif; color: #000000; } </style> <script type= "text/javascript" > var geocoder; var map; // initializing the map function initialize() { // define map center var latlng = new google.maps.LatLng(57.279043,29.355469); // define map options var myOptions = { zoom: 3, center: latlng, mapTypeId: google.maps.MapTypeId.HYBRID, scaleControl: true, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL }, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU } }; // initialize map map = new google.maps.Map(document.getElementById( "map_canvas" ), myOptions); // add event listener for when a user clicks on the map google.maps.event.addListener(map, 'click' , function (event) { findAddress(event.latLng); }); } // finds the address for the given location function findAddress(loc) { geocoder = new google.maps.Geocoder(); if (geocoder) { geocoder.geocode({ 'latLng' : loc}, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { address = results[0].formatted_address; // fill in the results in the form document.getElementById( 'lat' ).value = loc.lat(); document.getElementById( 'long' ).value = loc.lng(); document.getElementById( 'address' ).value = address; } } else { alert( "Geocoder failed due to: " + status); } }); } } // initialize the array of markers var markers = new Array(); // the function that adds the markers to the map function addMarkers() { // get the values for the markers from the hidden elements in the form var lats = document.getElementById( 'lats' ).value; var lngs = document.getElementById( 'lngs' ).value; var addresses = document.getElementById( 'addresses' ).value; var names = document.getElementById( 'names' ).value; var descrs = document.getElementById( 'descrs' ).value; var photos = document.getElementById( 'photos' ).value; var user_names = document.getElementById( 'user_names' ).value; var user_locs = document.getElementById( 'user_locs' ).value; var las = lats.split( ";;" ) var lgs = lngs.split( ";;" ) var ads = addresses.split( ";;" ) var nms = names.split( ";;" ) var dss = descrs.split( ";;" ) var phs = photos.split( ";;" ) var usrn = user_names.split( ";;" ) var usrl = user_locs.split( ";;" ) // for every location, create a new marker and infowindow for it for (i=0; i<las.length; i++) { if (las[i] != "" ) { // add marker var loc = new google.maps.LatLng(las[i],lgs[i]); var marker = new google.maps.Marker({ position: loc, map: window.map, title: nms[i] }); markers[i] = marker; var contentString = [ '<div id="tabs">' , '<ul>' , '<li><a href="#tab-1"><span>photo</span></a></li>' , '<li><a href="#tab-2"><span>description</span></a></li>' , '<li><a href="#tab-3"><span>location</span></a></li>' , '</ul>' , '<div id="tab-1">' , '<p><h1>' +nms[i]+ '</h1></p>' , '<p><img src="./photos/' +phs[i]+ '"/></p>' + '</div>' , '<div id="tab-2">' , '<p><h1>' +nms[i]+ '</h1></p>' , '<p>Added by: ' +usrn[i]+ ' from ' +usrl[i]+ '</p>' + '<p>' +dss[i]+ '</p>' + '</div>' , '<div id="tab-3">' , '<p><h1>' +nms[i]+ '</h1></p>' , '<p>Address: ' +ads[i]+ '</p>' + '<p>Location: ' +loc+ '</p>' + '</div>' , '</div>' ].join( '' ); var infowindow = new google.maps.InfoWindow; bindInfoWindow(marker, window.map, infowindow, contentString); } } } // make conection between infowindow and marker (the infowindw shows up when the user goes with the mouse over the marker) function bindInfoWindow(marker, map, infoWindow, contentString) { google.maps.event.addListener(marker, 'mouseover' , function () { map.setCenter(marker.getPosition()); infoWindow.setContent(contentString); infoWindow.open(map, marker); $( "#tabs" ).tabs(); }); } // highlighting a marker // make the marker show on top of the others // change the selected markers icon function highlightMarker(index) { // change zindex and icon for (i=0; i<markers.length; i++) { if (i == index) { markers[i].setZIndex(10); } else { markers[i].setZIndex(2); } } } </script> </head> <body onload= "initialize(); addMarkers()" > <?php // adding a new location to the db if (isset( $_POST [ 'name' ])) { $name = $_POST [ 'name' ]; $description = $_POST [ 'description' ]; $photo = $_FILES [ 'photo' ][ 'name' ]; $user_name = $_POST [ 'user_name' ]; $user_location = $_POST [ 'user_location' ]; $lat = $_POST [ 'lat' ]; $long = $_POST [ 'long' ]; $address = $_POST [ 'address' ]; // generate id $id = 1; $result = mysql_query( "select max(id) from locations" ); if (mysql_num_rows( $result ) != 0) { $row = mysql_fetch_array( $result ); $id = $row [ 'max(id)' ]+1; } // photo name $photo_name = "./photos/" . $id . "_photo.jpg" ; // sql query to add location $result = mysql_query("insert into locations (`id`, `name`, `latitude`, `longitude`, `address`, `photo`, `description`, `user_name`, `user_location`) values ( '$id' , '$name' , '$lat' , '$long' , '$address' , '$photo_name' , '$description' , '$user_name' , '$user_location' )"); //upload photo move_uploaded_file( $_FILES [ 'photo' ][ 'tmp_name' ], "./photos/" . $id . "_photo.jpg" ); //resize photo $simg = imagecreatefromjpeg( "./photos/" . $id . "_photo.jpg" ); $currwidth = imagesx( $simg ); $currheight = imagesy( $simg ); // new width = 200px $twidth = "200" ; $zoom = $twidth / $currwidth ; $newwidth = $twidth ; $newheight = $currheight * $zoom ; $dimg = imagecreatetruecolor( $newwidth , $newheight ); imagecopyresampled( $dimg , $simg , 0, 0, 0, 0, $newwidth , $newheight , $currwidth , $currheight ); imagejpeg( $dimg , "./photos/" . $id . "_photo.jpg" ); // update photo name $result = mysql_query( "update locations set `photo`='" . $id . "_photo.jpg' where id=" . $id ); } ?> <div id= "address_details" style= "width:100%; height:10%;" > <h1><center>Interactive Travel Map</center></h1> <?php $locations = mysql_query( "select * from locations" ); $nr_locations = mysql_num_rows( $locations ); ?> <br/>Click on the map to add a new location! Total locations added: <?php echo $nr_locations ;?> </div> <br/> <div id= "add" style= "width:25%; height:86%; float:left;" > <center><h1>Add a new location</h1></center> <br/> <form action= "index.php" method= "post" name= "add" id= "add" enctype= "multipart/form-data" onsubmit= "return check();" > <table align= "center" > <tr> <td><b>Name: </b></td> <td> </td> <td><input name= "name" id= "name" type= "text" size= "30" /></td> </tr> <tr> <td><b>Coordinates: </b></td> <td> </td> <td>lat: <input name= "lat" id= "lat" type= "text" size= "15" readonly/><br/>long: <input name= "long" id= "long" type= "text" size= "15" readonly/></td> </tr> <tr> <td><b>Address: </b></td> <td> </td> <td><input name= "address" id= "address" type= "text" size= "30" readonly/></td> </tr> <tr> <td><b>Description: </b></td> <td> </td> <td><textarea name= "description" id= "description" cols= "30" rows= "7" /></textarea></td> </tr> <tr> <td><b>Photo: </b></td> <td> </td> <td><input id= "photo" name= "photo" type= "file" /></td> </tr> <tr> <td colspan= "3" align= "center" > </td> </tr> <tr> <td colspan= "3" align= "center" > <table> <tr> <td colspan= "3" ><b>Who are you?</b></td> </tr> <tr> <td>Name:</td> <td> </td> <td><input name= "user_name" id= "user_name" type= "text" size= "25" /></td> </tr> <tr> <td>Location:</td> <td> </td> <td><input name= "user_location" id= "user_location" type= "text" size= "25" /></td> </tr> </table> </td> </tr> <tr> <td colspan= "3" align= "center" > </td> </tr> <tr> <td colspan= "3" align= "center" ><input type= "submit" value= "Add" /></td> </tr> </table> </form> </div> <div id= "map_canvas" style= "width:65%; height:86%; float:left;" ></div> <div id= "locations" style= "width:10%; height:86%; float:right; text-align: center" > <center><h1>Location list</h1></center> <br/> <?php // find locations from db // save data for locations $lats = "" ; // string with latitude values $lngs = "" ; // string with longitude values $addresses = "" ; // string with address values $names = "" ; // string with names $descrs = "" ; // string with descriptions $photos = "" ; // string with photo names $user_names = "" ; // string with user names $user_locs = "" ; // string with user locations $i =0; // take the locations from the db one by one while ( $locat = mysql_fetch_array( $locations )) { // add lcoation data to info strings $lats .= $locat [ 'latitude' ]. ";;" ; $lngs .= $locat [ 'longitude' ]. ";;" ; $addresses .= $locat [ 'address' ]. ";;" ; $names .= $locat [ 'name' ]. ";;" ; $descrs .= $locat [ 'description' ]. ";;" ; $photos .= $locat [ 'photo' ]. ";;" ; $user_names .= $locat [ 'user_name' ]. ";;" ; $user_locs .= $locat [ 'user_location' ]. ";;" ; // show the location name in the right of the map with link that calls the highlightMarker function ?> <a onmouseover= "highlightMarker(<?php echo $i;?>)" ><?php echo $locat [ 'name' ];?></a> <br/> <?php $i ++; } // hidden inputs for saving the info for all the locations in the db ?> <input type= "hidden" value= "<?php echo $lats;?>" id= "lats" name= "lats" /> <input type= "hidden" value= "<?php echo $lngs;?>" id= "lngs" name= "lngs" /> <input type= "hidden" value= "<?php echo $addresses;?>" id= "addresses" name= "addresses" /> <input type= "hidden" value= "<?php echo $names;?>" id= "names" name= "names" /> <input type= "hidden" value= "<?php echo $descrs;?>" id= "descrs" name= "descrs" /> <input type= "hidden" value= "<?php echo $photos;?>" id= "photos" name= "photos" /> <input type= "hidden" value= "<?php echo $user_names;?>" id= "user_names" name= "user_names" /> <input type= "hidden" value= "<?php echo $user_locs;?>" id= "user_locs" name= "user_locs" /> </div> </body> </html> databse |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | database -- phpMyAdmin SQL Dump -- version 3.2.0.1 -- http: //www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Sep 16, 2010 at 10:11 AM -- Server version: 5.1.36 -- PHP Version: 5.3.0 -- -- Table structure for table `locations` -- CREATE TABLE IF NOT EXISTS `locations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `description` text NOT NULL, `photo` text NOT NULL, `latitude` double NOT NULL, `longitude` double NOT NULL, `address` text NOT NULL, `user_name` text NOT NULL, `user_location` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ; |

ความคิดเห็นที่
2
1 2 3 4 5 6 7 8 9 10 11 | connect.php <?php $server = "WRITE_SERVER_NAME_HERE" ; $username = "WRITE_USERNAME_HERE" ; $password = "WRITE_PASSWORD_HERE" ; $database = "WRITE_DATABASE_NAME_HERE" ; $connId = mysql_connect( $server , $username , $password ) or die ( "Cannot connect to server" ); $selectDb = mysql_select_db( $database , $connId ) or die ( "Cannot connect to database" ); ?> |

ขอบคุณทุกการสนับสนุน
![]()