从
数据库的此条目中获取每个数据块的正确方法是什么?
我正在为wordpress自定义一个名为自定义联系表单的插件,基本上对于收到的每封电子邮件,都会使用以下格式在数据库上创建一个新条目:
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
问题标题中提到的一种或两种方法都是错误的,我不知道该怎么做:(
提前致谢
编辑:多亏了富尔哈克,我现在有了这个...
$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",因为数据库中有条目。
尝试使用
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"];
不过,您可能应该添加一些错误检查。