简体   繁体   中英

extract details from any particular row cell of mysql

I want to know how to extract details from any particular row cell in a MySQL database. These details are in a cell in a MySQL table. Specifically, I want to extract the value of

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

I have this:

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";}}";}

if i understand you correctly this cell information has been save using serialization http://php.net/manual/en/function.serialize.php

You need to unserialize http://www.php.net/manual/en/function.unserialize.php it before you can extract the information you require ..

Example

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

Output

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)

The information you want

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM