-1

I want to be able to select all rows where a value matches with the one I'm calling for in php This is what I have for now and the only thing I get is the first row. Not the other rows.

<?php>
session_start();
require "db.inc.php";

$id = $_SESSION['userId'];

$sql = "SELECT followingId FROM following WHERE followerId=$id";
$sth = $conn->query($sql);
if(!$sth) {
echo("Error description: " . mysqli_error($conn));
die();
}
$result = mysqli_fetch_array($sth);

echo var_dump($result);

$followedId = $result['followingId'];

echo $followedId;

And $conn is the connection variable in db.inc.php

2
  • 1
    Load mysqli_fetch_array in a loop... you will find tons of examples if you google once Commented Oct 25, 2018 at 10:54
  • Look over here at stackoverflow.com/questions/6481806/… Commented Oct 25, 2018 at 10:54

1 Answer 1

1

You must iterate through the results array you are fetching

while ($row = mysqli_fetch_array($result)) {
     foreach($row as $field => $value) {
          //do something with $field and $val
     }
}  
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! My code now have ur function and I'm echoing out $value and gets the strings I want but I get each two times The output is 232324242525 I just want 23 24 25
@Kevlar2228 please update your answer or post a new one, without seeing any code it is difficult to give any help