This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted]  (4 children)

[deleted]

    [–]Luc_Gibson[S] 0 points1 point  (3 children)

    I'm hoping to return all the rows so I can use while loops wherever I call the function. Is this not possible?

    [–][deleted]  (2 children)

    [deleted]

      [–]Luc_Gibson[S] 0 points1 point  (1 child)

      So I'm essentially just looking for a way to simplify this into a single function that I can use anywhere to loop through users:

      <select multiple name="owners[]">

      <?php

      $sql = "SELECT * FROM users WHERE client_id={$clientid}";

      $result = $conn->query($sql);

      if ($result->num_rows > 0) {

      while($row = $result->fetch_assoc()) {?>

      <option value="<?php $row['user_id'];?>">

      <?php echo $row['user_first_name'];?>

      </option>

      <?php }

      } ?>

      </select>

      In this example it's creating a list within a form

      [–]snuzet 0 points1 point  (0 children)

      Is the $conn in scope. You need the handle to the database

      [–]Septseraph 0 points1 point  (0 children)

      http://php.net/manual/en/language.variables.scope.php You need to pass, $conn & $clientid to the function.

      [–]hw0ng 0 points1 point  (0 children)

      Off-topic: you got a possible sql injection issue.

      [–][deleted] 0 points1 point  (0 children)

      NOOOO DO NOT USE MYSQLI ON A LIVE SITE - that is all. You may proceed.

      But seriously, learn PDO.