Last active
December 16, 2015 19:29
-
-
Save kbjr/5485117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mysql = mysqli_connect("localhost","root","","test"); | |
if (mysqli_connect_errno($mysql)){echo "Failed to connect to database";} | |
$user = "rebel24"; | |
$input = mysqli_query($mysql,"SELECT * FROM `userdata` WHERE `Username` = '$user';"); | |
//while ($row = mysqli_fetch_array($input)){ | |
//foreach(explode(";", $row['SkillData']) as $pair) | |
// foreach (explode(":", $pair) as $name => $val) | |
//echo "$val<br>"; } | |
$data = mysqli_fetch_array($input); | |
# We store the final result here | |
$skill_data = array(); | |
# Explode the data into an array | |
$fields = explode(';', $data); | |
# Run through the fields copying them over in the format we want | |
foreach ($fields as $field) { | |
# Ignore the empty one at the end created by the ending semi-colon | |
if (! empty($field)) { | |
# Separate the field name from it's value | |
$field = explode(':', $field); | |
$skill_data[$field[0]] = $field[1]; | |
} | |
} | |
# You can now get fields like | |
echo $skill_data['Flying']; | |
mysqli_close($mysql); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment