简体   繁体   English

从mysql数据库的单个“单元”中的大量数据中提取特定数据

[英]Extracting specific data from a large amount of data in a single “cell” of a mysql database

Long time reader first time questioner... 长期读者第一次发问者...

I'm attempting to use Drupal to create a set of variables, not the issue, it's all in place to set them and simple for the future operator to edit. 我正在尝试使用Drupal创建一组变量,而不是问题,所有这些都可以设置它们,并且方便将来的操作员进行编辑。

I then need to grab these values in php, still on the site but outside of Drupal to some extent. 然后,我需要在php中获取这些值,但仍在站点上,但是在一定程度上在Drupal之外。 Again, although I'm a bit of a lightweight on PHP, I can get what I need. 同样,尽管我对PHP有点轻量级,但是我可以得到所需的东西。 However drupal stores the data all in one "cell" (apologies, I've searched for what I'm after but I think my vocabulary is lacking to get the right result!). 但是drupal将数据全部存储在一个“单元”中(抱歉,我一直在寻找我想要的东西,但我认为我的词汇量不足以获得正确的结果!)。 Here's an example of how it is stored: 这是一个如何存储它的例子:

a:3:{i:0;a:3:{s:5:"value";s:2:"38";s:5:"label";s:11:"Cost Per M2";s:6:"weight";s:1:"0";}i:1;a:3:{s:5:"value";s:1:"7";s:5:"label";s:13:"Arch Top Cost";s:6:"weight";s:1:"1";}i:2;a:3:{s:5:"value";s:1:"5";s:5:"label";s:13:"Flat Top Cost";s:6:"weight";s:1:"2";}} a:3:{i:0; a:3:{s:5:“ value”; s:2:“ 38”; s:5:“ label”; s:11:“每M2成本”; s: 6:“ weight”; s:1:“ 0”;} i:1; a:3:{s:5:“ value”; s:1:“ 7”; s:5:“ label”; s: 13:“拱门最高成本”; s:6:“重量”; s:1:“ 1”;} i:2; a:3:{s:5:“值”; s:1:“ 5”; s:5:“标签”; s:13:“单位最高费用”; s:6:“重量”; s:1:“ 2”;}}

So I can happily return the whole contents as above, but I haven't the slightest how to refine it down to a specific reference. 因此,我可以很高兴地返回上面的全部内容,但是我丝毫没有将其细化为特定参考的方法。 I can work out the data is contained between certain sets of brackets so, one ref is: 我可以算出数据包含在某些括号之间,因此,一个参考是:

{s:5:"value";s:2:"38";s:5:"label";s:11:"Cost Per M2";s:6:"weight";s:1:"0";}

What I really need is the "38" in the example, as this is a cost that a 2nd system uses a number of to calculate a final cost. 我真正需要的是示例中的“ 38”,因为这是第二系统使用多个来计算最终成本的成本。

I hope this makes sense? 我希望这是有道理的?

The value is serialised (see http://php.net/manual/en/function.serialize.php ). 该值已序列化(请参阅http://php.net/manual/en/function.serialize.php )。 What you want to do is unserialize it (see http://www.php.net/manual/en/function.unserialize.php ). 您要做的是将其反序列化(请参阅http://www.php.net/manual/zh/function.unserialize.php )。 So it would be: 因此它将是:

$deserializedValues = unserialize($values). 

After that you can call the variables by doing: 之后,您可以通过以下方式调用变量:

$deserializedValues['value'] (if an array)

$deserializedValues->value (if an object)

Drupal returns JSON. Drupal返回JSON。 The cleanest way to handle this would be to use PHP's json_decode() function: http://php.net/manual/en/function.json-decode.php 解决此问题的最干净方法是使用PHP的json_decode()函数: http ://php.net/manual/zh/function.json-decode.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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