How to Extract Data from a field with multiple values?

IP.Nexus puts custom fields into a table all muddled up into one row and some how pulls the correct data out.

basically my custom fields row looks like so:

a:2:{i:2;s:4:"Test";i:3;s:10:"Accounting";}

How do i select what item to pull as i would like to out put just one item not the whole row, is it with delimiters or string splitter, as i am novice with this part of mySQL

Cause i would like to echo out just the advertising on its own and also vice versa for the testing.

Thanks in advance

Answers


It's a serialized array using serialize() function so you can get its contents using unserialize($YourString);.

But I see that you string is corrupted for deserialization, because s:4: in s:4:"advertising" says that after s:4: 4 character long string is expected that advertising is not.


The data in the database is in serialized(json) form.You can turn it into simple array using unserialize. For example;if $mystr is your string write

$mystring=unserialize($mystring)

You will get normal array of this string You can do

foreach($mystring as $str){
$ads[]=$str['advertising'];
}

and the resulting array $ads will be the ads you like in simple array form


Since this looks as JSon, you can use a PHP JSon module to parse each row from MySQL.

<?php

(...)
while (...) {
    $obj = json_decode($row);
    // do something with $obj
}

Need Your Help

doxygen - automatically append text for when a page was last edited?

doxygen

Is it possible to get doxygen (http://www.doxygen.nl/index.html) to automatically add some text to each generated page that states when the page was last modified due to a code (or comment) change?

Neo4j which Traversal should one use?

java neo4j deprecated graph-traversal

I'm currently trying Neo4J Koan Tutorial. I'm getting really confused at Koan06 where Traversal are introduced. Method Node.traversal is deprecated in favour for Traversal.traverse. As I tried it, ...