-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

  • 1
    Load `mysqli_fetch_array` in a loop... you will find tons of examples if you google once – B001ᛦ Oct 25 '18 at 10:54
  • Look over here at https://stackoverflow.com/questions/6481806/how-to-select-multiple-rows-from-mysql-with-one-query-and-use-them-in-php – B. Cratty Oct 25 '18 at 10:54

1 Answers1

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
     }
}  
Andrea Golin
  • 3,259
  • 1
  • 17
  • 23
  • 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 –  Oct 26 '18 at 08:17
  • @Kevlar2228 please update your answer or post a new one, without seeing any code it is difficult to give any help – Andrea Golin Oct 26 '18 at 10:26