Well, let's talk about....
while($r= $result->fetch_array(MYSQL_ASSOC))
What you are doing here is setting $r
as an associative array, then setting that full array inside $rows
; so if $result
did return anything, it would be multiplied inside $rows
.
Maybe what you are after is something like this?
$prep =$mysqli->prepare("select name,location from token where sen_uid=?");
//should the bind_param function be i instead of s? i means integer and s means string
//$prep->bind_param("i",$id);
$prep->bind_param("s",$id);
$prep->execute();
$result= $prep->get_result();
$rows= array();
//for an array like [0][0], [0][1] use
//$rows= $result->fetch_array(MYSQLI_NUM);
//for an arary like [0]['name'], [0]['location'] use:
$rows= $result->fetch_array(MYSQLI_ASSOC);
$obj= json_encode($rows);
The execution of the query looks correct. I'd maybe add some error checking to ensure that prepare didn't fail. Have you tried running this query inside MySQL to see if you get results?
Edit; In fact, while
is completely pointless in this as $r
would only ever be set once. I think this issue sits mainly within a broken prepared query.
if($prep =$mysqli->prepare("select name,location from token where sen_uid=?")){
//should the bind_param function be i instead of s? i means integer and s means string
//$prep->bind_param("i",$id);
$prep->bind_param("s",$id);
if(!$prep->execute()){
print_r("Execute error: ".$mysqli->error);
}
$result= $prep->get_result();
$rows= array();
//for an array like [0][0], [0][1] use
//$rows= $result->fetch_array(MYSQLI_NUM);
//for an arary like [0]['name'], [0]['location'] use:
$rows= $result->fetch_array(MYSQLI_ASSOC);
$obj= json_encode($rows);
}else{
print_r("Prepare error: ".$mysqli->error);
}
For debugging purposes, add error checking like the above snippet