0

从我的数据库中的这个条目中获取每个数据块的正确方法是什么?

我正在为 wordpress 定制一个名为 custom contact forms 的插件,基本上对于收到的每封电子邮件,都会在数据库中创建一个新条目,格式如下:

s:8:"enq_name";s:3:"ICE";s:9:"enq_email";s:23:"xvxvxv@hotmail.com";s:9:"enq_phone";s:10:"9191919191";s:11:"enq_message";s:74:"bla bla bla bla and more bla bla bla";s:10:"enq_footer";s:288:"This message has been set to you by my";

如何获取单个值,例如消息enq_message

如果问题标题中提到的一种或两种方法有误,我深表歉意,我不知道如何做到这一点:(

提前致谢

编辑: 感谢fulhack,我现在有了这个......

$query = "SELECT * FROM `$table_name` WHERE `data_formid` = $ff ORDER BY `$table_name`.`id` ASC LIMIT 0, 5";     
$result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    echo $myDate = date( 'd/M/Y', $row['data_time'] );
    $string = $row['data_value'];

    $serialized = $string;
    $unserialized = unserialize($serialized);
    $theValue = $unserialized['enq_email'];

    echo $theValue;
    }

但这仅与“e”或更精确的“eeeee”相呼应,因为数据库中有条目。

4

1 回答 1

2

尝试使用 unserialize() (http://www.php.net/manual/en/function.unserialize.php),然后使用密钥(enq_message在您的情况下)检索您正在寻找的值。

编辑:我无权访问 PHP 安装,但我认为这可行:

$serialized = serialize(array("key" => "value")); // This is the data you supplied
$unserialized = unserialize($serialized);
$theValue = $unserialized["key"];

不过,您可能应该添加一些错误检查。

于 2012-05-20T10:31:14.590 回答