ขอถามวิธีเก็บค่าแบบ Array ลงฐานข้อมูล ว่าต้องทำยังไงค่ะ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ขอถามวิธีเก็บค่าแบบ Array ลงฐานข้อมูล ว่าต้องทำยังไงค่ะ

ขอถามวิธีเก็บค่าแบบ Array ลงฐานข้อมูล ว่าต้องทำยังไงค่ะ

สวัสดีค่ะ พอดีนู๋ได้ code นี้มาจากเว็บ http://www.jquerytips.com/ 
แล้วสงสัยว่าถ้าเกิดว่าจะเก็บนำข้อมูล $response นี้เก็บต่อในฐานข้อมูลต้องทำอย่างไรค่ะ

ข้อมูลที่ว่า มันอยู่ในรูปแบบของ array ค่ะ ต้องทำยังไงค่ะ 

ช่วยด้วยนะค่ะ
ขอบคุณค่ะ

<?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"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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; ?>'
        redirect-uri="http://www.osdev.com/APIs/facebook/facebook-tools/registration.php?action=save"
        width="530">
    </fb:registration>
 
    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script type="text/javascript" >
        FB.init({
            appId  : '<?php echo $facebook->getAppId(); ?>',
            status : true,
            cookie : true,
            xfbml  : true
        });
    </script>
 
  </body>
</html>

 



Lkpoi 110.164.39.xxx 30-06-2011 14:46:39

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1

 ใช้คำสั่ง print_r() หาโครงสร้างของตัวแปร array

 
เอาโค้ดนี้ไปรันดู ไว้ต่อท้ายจากตัวแปร array ชื่อ $custom_fields
<pre>
<?php print_r($custom_fields); ?>
</pre>
 
 
แล้วไปไล่ตัวแปร ตามโครงสร้าง ค่าของตัวแปรคือตัวที่อยู่ในสุด คือ ต่อจาก เครื่องหมาย  =>
 
อย่างชื่อตัวแปร ของค่า Jean-Luc Picard 
 
คือ 
$custom_fields[9]['options']['P']
 
 
จะได้
$custom_fields[9]['options']['P']="Jean-Luc Picard";
 


Ninenik 183.89.143.xxx 30-06-2011
 ความคิดเห็นที่ 2

แล้วถ้าเราต้องการ ค่าที่เค้ากรอกให้อ่าค่ะ เช่น

Name : <input type="text" name="name" value="<?php echo $custom_fields[0];?>"> 

นู๋จะให้แสดงชื่อที่เค้า login อยู่ใน facebook ออกมา แต่สิ่งที่มันออกมาคือ คำว่า name อ่าค่ะ แล้ว

ไม่ทราบว่านู๋ต้องทำอย่างไหรหรอค่ะ

จุดประสงค์ของนู๋คือ ต้องการใส่ค่าต่าง ๆ ไว้ใน textbox แล้วเอาข้อมูลนี้ส่งเป็นค่า Post บันทึกเข้าฐานข้อมูลอ่าค่ะ

ถ้ายังไงช่วยด้วยนะค่ะ ขอบคุณมากๆๆๆค่ะ



lkpoi 110.164.39.xxx 30-06-2011 17:32
 ความคิดเห็นที่ 3

 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);

คร่าวๆ ครับ



wissanu10712 124.120.71.xxx 23-11-2011 11:20
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ