Note that there are some explanatory texts on larger screens.

plurals
  1. PO$_POST[ ] and mysql_fetch_arrays together
    primarykey
    data
    text
    <p>I'm working on outputting data from two different sources into an HTML table. One source is a <code>mysql_fetch_array</code>, the other is a <code>$_POST</code> array. There are three <code>&lt;td&gt;</code> tables from mysql and one from <code>$_POST</code> outputting via a while loop. To associate the arrays on the output page, I planned to store the <code>$_POST</code> data in the table via the row id and then query the whole row further down the page.</p> <p>The issue I have is that I can't seem to get the <code>$_POST</code> array values UPDATED into the row correctly. The last value in the <code>$_POST</code> array is all what's stored in all selected fields.</p> <p>The input page arrays are captured with <code>id [ ]</code> and <code>unit_ass[ ]</code> and are passed to the output page.</p> <p>The output page code:</p> <pre><code>require_once ("../includes/db_connect.inc"); $pid = array_filter($_POST['id']); $gid = implode(",", $pid); $sua = array_filter($_POST['unit_ass']); foreach($sua as $value) echo $value . "&lt;br&gt;"; // this outputs correct values in the correct order. foreach($sua as $value) mysql_query("UPDATE $tbl_name SET unit_ass='$value' WHERE id IN ( $gid )"); </code></pre> <p>Just stripping empty keys with <code>array_filter()</code> ... When I echo the values in the first foreach statement, they are displayed correctly and in correct order.</p> <p>However, only the last value from the <code>$sua</code> array is updating the table rows as determined by $gid. The foreach isn't iterating the array values and performing the UPDATE as it should. The data via <code>id[ ]</code> is displayed correctly further down the page via a <code>mysql_fetch-array</code> in a while loop.</p> <p>I've been staring at this for several hours now and can't seem to find the solution. Any help is appreciated.</p>
    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.
 

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