Note that there are some explanatory texts on larger screens.

plurals
  1. POUsers list, follow button not working properly
    primarykey
    data
    text
    <p>I've created a page which displays all the users on the site. </p> <p>The <strong>user_id</strong> and the <strong>username</strong> is displayed for each user. I tried adding a <strong>follow</strong> button at the side of each user and in order to <strong>follow</strong> someone it grabs their <strong>user_id</strong>. </p> <p>Unfortunately I can't get it to work because the <strong>user_id</strong> which is being grabbed is always the <strong>last one</strong> from the <strong>database</strong>, because of the loop.</p> <p>So if you press the <strong>follow</strong> button for <strong>anyone</strong> on the list, it will always <strong>follow</strong> the <strong>last</strong> person. </p> <p>How can I fix this?</p> <p>I've been trying different methods for more than 20 hours but they all seem to have the same problem... </p> <p>Here is the code:</p> <pre><code>&lt;?php class Database() { // connect // query public function fetchAll() { $this-&gt;rows = $this-&gt;result-&gt;fetch_all(MYSQLI_ASSOC); return $this-&gt;rows; } public function display() { $this-&gt;query("SELECT * FROM `users`"); $this-&gt;fetchAll(); } } $class = new Database(); $users = $class-&gt;display(); foreach ($users as $user) { $user_id = $user['user_id']; $username = $user['username']; echo $user_id . ' ' . $username; echo '&lt;form action="" method="post"&gt;'; echo '&lt;input type="submit" name="follow" value="Follow"&gt;'; echo '&lt;/form&gt;'; } if ($_POST['follow']) { $FClass-&gt;follow($user_id); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload