从mysql的任何特定行单元格中提取细节

时间:2012-05-12 18:03:51

标签: php mysql

我想知道如何从MySQL数据库中的任何特定行单元格中提取细节。这些详细信息位于MySQL表的单元格中。具体来说,我想提取

的值
cwall_id which is photos1187       
uri    which is photos/viewstory/1187
name     which is nmart
thumb which is uploads/userfiles/201205/13_03_pceb9.jpg

我有这个:

a:1:{i:0;s:275:"a:4:{s:8:"cwall_id";s:10:"photos1187";s:3:"uri";s:21:"photos/viewstory/1187";s:4:"name";s:5:"nmart";s:5:"thumb";a:3:{i:0;s:40:"uploads/userfiles/201205/13_03_pceb9.jpg";i:1;s:40:"uploads/userfiles/201205/13_03_0wlih.jpg";i:2;s:40:"uploads/userfiles/201205/13_03_tq5wf.jpg";}}";}

1 个答案:

答案 0 :(得分:2)

如果我理解正确,则使用序列化http://php.net/manual/en/function.serialize.php

保存此单元格信息

在您提取所需信息之前,您需要unserialize http://www.php.net/manual/en/function.unserialize.php

实施例

$cell = 'a:1:{i:0;s:275:"a:4:{s:8:"cwall_id";s:10:"photos1187";s:3:"uri";s:21:"photos/viewstory/1187";s:4:"name";s:5:"nmart";s:5:"thumb";a:3:{i:0;s:40:"uploads/userfiles/201205/13_03_pceb9.jpg";i:1;s:40:"uploads/userfiles/201205/13_03_0wlih.jpg";i:2;s:40:"uploads/userfiles/201205/13_03_tq5wf.jpg";}}";}';
$list = unserialize($cell);
$info = unserialize($list[0]);
var_dump($info);

输出

array
  'cwall_id' => string 'photos1187' (length=10)
  'uri' => string 'photos/viewstory/1187' (length=21)
  'name' => string 'nmart' (length=5)
  'thumb' => 
    array
      0 => string 'uploads/userfiles/201205/13_03_pceb9.jpg' (length=40)
      1 => string 'uploads/userfiles/201205/13_03_0wlih.jpg' (length=40)
      2 => string 'uploads/userfiles/201205/13_03_tq5wf.jpg' (length=40)

您想要的信息

echo $info['cwall_id'] ;
echo $info['uri'] ;
echo $info['thumb'][1] ;