i want have 1 array these 2 tags can reference through client using either tag index
$query = "select username,imgdefault users" $result = $sql->query($query); $rows = array(); while($row = $result->fetch_assoc()) { $rows[]=$row; } $result->close(); $sql->close(); $str = implode(',', array_map(function($el){ return $el['username']; }, $rows)); $str1 = implode(',', array_map(function($el){ return $el['imgdefault']; }, $rows)); desired output array
username:"d" imgdefault: "a", username:"b" imgdefault: "q", etc.... im open other output me identify column value on index
if understood correctly you're trying have possibility "username" based on "imgdefault" or "imgdefault" based on "username".
you should first associative array key username, , value imgdefault: $query = "select username,imgdefault users" $result = $sql->query($query);
$associativearray = array(); while($row = $result->fetch_assoc()) { $currusername = $row["username"]; $currimgdefault = $row["imgdefault"]; $associativearray[$currusername]= $currimgdefault; } $result->close(); $sql->close(); // $array array("d" => "a", "b" => "q", ...); then can "imgdefault" based on "username" using:
if (array_key_exists($theusername, $associativearray)) { $theimgdefault = $associativearray[$theusername]; } and can "username" based on "imgdefault" using:
$theusername = array_search($theimgdefault,$associativearray);
Comments
Post a Comment