ขอถามวิธีเก็บค่าแบบ Array ลงฐานข้อมูล ว่าต้องทำยังไงค่ะ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ขอถามวิธีเก็บค่าแบบ Array ลงฐานข้อมูล ว่าต้องทำยังไงค่ะ
สวัสดีค่ะ พอดีนู๋ได้ code นี้มาจากเว็บ http://www.jquerytips.com/
แล้วสงสัยว่าถ้าเกิดว่าจะเก็บนำข้อมูล $response นี้เก็บต่อในฐานข้อมูลต้องทำอย่างไรค่ะ
ข้อมูลที่ว่า มันอยู่ในรูปแบบของ array ค่ะ ต้องทำยังไงค่ะ
ช่วยด้วยนะค่ะ
ขอบคุณค่ะ
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 | <?php require ( 'facebook.php' ); $facebook = new Facebook( array ( 'appId' => 'YOUR_FACEBBOK_APP_ID' , 'secret' => 'YOUR_FACeBOOK_APP_SECRET' , 'cookie' => true, )); $action = (isset( $_GET [ 'action' ])) ? $_GET [ 'action' ] : false; if ( $action == 'save' ) { $signed_request = $_POST [ 'signed_request' ]; $response = $facebook ->parseSignedRequest( $signed_request ); echo "<pre>" . print_r( $response , true) . "</pre>" . "n" ; exit (0); } $custom_fields = array ( array ( 'name' => 'name' ), array ( 'name' => 'email' ), array ( 'name' => 'location' ), array ( 'name' => 'gender' ), array ( 'name' => 'birthday' ), array ( 'name' => 'password' , 'view' => 'not_prefilled' ), array ( 'name' => 'like' , 'description' => 'Do yout like this plugin?' , 'type' => 'checkbox' , 'default' => 'checked' ), array ( 'name' => 'phone' , 'description' => 'Phone Number' , 'type' => 'text' ), array ( 'name' => 'anniversary' , 'description' => 'Anniversary' , 'type' => 'date' ), array ( 'name' => 'captain' , 'description' => 'Best Captain' , 'type' => 'select' , 'options' => array ( 'P' => 'Jean-Luc Picard' , 'K' => 'James T. Kirk' ) ), array ( 'name' => 'force' , 'description' => 'Which side?' , 'type' => 'select' , 'options' => array ( 'jedi' => 'Jedi' , 'sith' => 'Sith' ), 'default' => 'sith' ), array ( 'name' => 'live' , 'description' => 'Best Place to Live' , 'type' => 'typeahead' , 'categories' => array ( 'city' , 'country' , 'state_province' ) ), array ( 'name' => 'captcha' ) ); $custom_fields_json = json_encode( $custom_fields ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "en" lang= "en" xmlns:fb= "http://www.facebook.com/2008/fbml" > <head> <title>Facebook Registration Tool</title> <meta http-equiv= "content-type" content= "text/html;charset=UTF-8" /> <style type= "text/css" > body { font-family: 'Lucida Grande' , Verdana, Arial, sans-serif; } </style> </head> <body> <fb:registration fields= '<?php echo $custom_fields_json; ?>' width= "530" > </fb:registration> <div id= "fb-root" ></div> <script type= "text/javascript" > FB.init({ appId : '<?php echo $facebook->getAppId(); ?>' , status : true, cookie : true, xfbml : true }); </script> </body> </html> |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ใช้คำสั่ง print_r() หาโครงสร้างของตัวแปร array
1 2 3 | <pre> <?php print_r( $custom_fields ); ?> </pre> |
1 | $custom_fields [9][ 'options' ][ 'P' ] |
1 | $custom_fields [9][ 'options' ][ 'P' ]= "Jean-Luc Picard" ; |

แล้วถ้าเราต้องการ ค่าที่เค้ากรอกให้อ่าค่ะ เช่น
1 | Name : <input type= "text" name= "name" value= "<?php echo $custom_fields[0];?>" > |
นู๋จะให้แสดงชื่อที่เค้า login อยู่ใน facebook ออกมา แต่สิ่งที่มันออกมาคือ คำว่า name อ่าค่ะ แล้ว
ไม่ทราบว่านู๋ต้องทำอย่างไหรหรอค่ะ
จุดประสงค์ของนู๋คือ ต้องการใส่ค่าต่าง ๆ ไว้ใน textbox แล้วเอาข้อมูลนี้ส่งเป็นค่า Post บันทึกเข้าฐานข้อมูลอ่าค่ะ
ถ้ายังไงช่วยด้วยนะค่ะ ขอบคุณมากๆๆๆค่ะ

foreach($_POST[a] as $i => $value)
{
$a = $_POST['a'][$i];
$a = $_POST['b'][$i];
$sql = "insert into data set a='$a',b='$b' ";
$query = mysql_query($sql);
คร่าวๆ ครับ
