Reputation: 33
I have a MySQL table with a ton of users, each user have a row ("details")
Data example of a user:
["D11","E20","E70","E50","D50","G32"]
Each user could have more or none data.
Currently I fetch this data per user with a simple
while ($row = pg_fetch_array($resultado)) {
$details = $row["details"];
}
What I want is to be able to select the 1, 2, 3 and 4 item from this "array" or "json" not sure what it is or how to format it correctly.
I wanna be able to just save this first item in a custom var, like
MainDetail = "D11";
I tried with json encode, serialize, without luck :/
Upvotes: 3
Views: 42
Reputation: 72299
Actually you have saved string inside column and you think that either it's an array or serialize/json data.
Please do like below:-
while ($row = pg_fetch_array($resultado)) {
echo $details = str_replace(array('[','"'),'',explode(",",$row["details"])[0]);
}
Upvotes: 1