Note that there are some explanatory texts on larger screens.

plurals
  1. POforeach loop duplicating first row
    primarykey
    data
    text
    <p>This is the code that I have</p> <pre><code>&lt;?php $checkbox = $_REQUEST['checkbox']; for($i=0; $i&lt;count($_REQUEST['checkbox']); $i++){ $del_id = $checkbox[$i]; $get_info=$db-&gt;prepare("SELECT * FROM `pending_payments` WHERE `id` = ?"); $get_info-&gt;bind_param('i', $del_id); $get_info-&gt;execute(); $result = $get_info-&gt;get_result(); $info[] = $result-&gt;fetch_assoc(); foreach($info as $row){ $amount = $row['amount']; $email = $row['email']; echo" &lt;input type='text' style='height: 35px;' name='Amount[]' value='".$amount."' /&gt; &lt;input type='text' style='height: 35px;' name='EmailAddress[]' value='".$email."' /&gt;&lt;br /&gt; "; } } ?&gt; </code></pre> <p>The problem that I am having is that it is duplicating the first row it finds. I have 2 entries into the database, and it is repeating the first row twice before going on the the third, when I <code>print_r</code> <code>$info</code> it gives me this</p> <pre><code>Array ( [0] =&gt; Array ( [id] =&gt; 1 [username] =&gt; ccarson030308 [amount] =&gt; 5.00 [processor] =&gt; PayPal [email] =&gt; ccarson030308@gmail.com [submitted_date] =&gt; 1372030166 ) ) </code></pre> <p>then shows the <code>echo</code> for that line then starts over and shows </p> <pre><code>Array ( [0] =&gt; Array ( [id] =&gt; 1 [username] =&gt; ccarson030308 [amount] =&gt; 5.00 [processor] =&gt; PayPal [email] =&gt; ccarson030308@gmail.com [submitted_date] =&gt; 1372030166 ) [1] =&gt; Array ( [id] =&gt; 2 [username] =&gt; tatsu91 [amount] =&gt; 5.00 [processor] =&gt; PayPal [email] =&gt; sheynever@yahoo.com [submitted_date] =&gt; 1372030166 ) ) </code></pre> <p>which should be the only thing it shows to begin with, do I have something wrong in my <code>for</code> loop? I don't normally loop <code>for</code> and <code>foreach</code> but it seemed to be the best method for what I am trying to do, but I am failing somehow.</p> <p>Without adding the append <code>[]</code> I get 12 errors of <code>Warning: Illegal string offset 'amount' Warning: Illegal string offset 'email'</code></p>
    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.
    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