Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Buttons inside loop
    primarykey
    data
    text
    <p>I have a problem and I don't know how to sove it.I have an inventory table that contains an id (that is assign to a user)column and id_item column (that is assign to an item from items table) and an items table that also contains an id table.</p> <p>More specifically this is what my database contains: items table:</p> <pre><code>id name 1 Dagger 2 Staff 3 Wood Shield </code></pre> <p>Each with his unique id.</p> <p>Inventory table:</p> <pre><code>id id_item username name 1 3 cristi Wood Shield 2 1 motoc Dagger 2 2 motoc Staff </code></pre> <p>The id is from every user id and id_item is the item's id from items table.</p> <p>Problem: Let's say I'm logged in as motoc who has 2 weapons in his inventory. Til now everything is fine. I want to make a button for every item that he has. The buttons are there but not working properly. When I click the first one is shows me ssss1 which is correct but when I press the second one nothing hapens. I want to show me ssss2 more specifically the next $row1['id_item']. </p> <p>I really don't know how to solve this. Thank you.</p> <p>This is what i've tried:</p> <pre><code>if (isset($_SESSION['id'])) { $sth1 = $dbh-&gt;prepare("SELECT * FROM inventory WHERE id = ".$_SESSION['id'].""); $sth1-&gt;execute(); while($row1 = $sth1-&gt;fetch(PDO::FETCH_ASSOC)){ $sth = $dbh-&gt;prepare("SELECT * FROM items WHERE id = ".$row1['id_item'].""); $sth-&gt;execute(); $row = $sth-&gt;fetch(PDO::FETCH_ASSOC); $ss = print $row1["id_item"]; ?&gt; &lt;form id='&lt;?php echo $row1["id_item"]; ?&gt;' method="POST" action="" &gt; &lt;input type="hidden" name="refid" value="add" /&gt; &lt;input type="submit" name="submit&lt;?php echo $row1["id_item"]; ?&gt;" value="Add" /&gt; &lt;/form&gt; &lt;?php } if (isset($_POST["submit$ss"])) { $refid = intval($_POST["refid"]); $sth1 = $dbh-&gt;prepare("SELECT * FROM inventory WHERE id = ".$_SESSION['id'].""); $sth1-&gt;execute(); $row1 = $sth1-&gt;fetch(PDO::FETCH_ASSOC); echo "ssss".$row1['id_item']; } } </code></pre>
    singulars
    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