Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i insert 2 concatenated arrays to a certain part of a table in php
    primarykey
    data
    text
    <p>I have extensively searched the web for this but haven't found anything that can help!</p> <p>At the moment I have three loops:</p> <pre><code>// loop 1 finds the answers if(isset($_POST['qanswer'])){ ($question = $_POST['qanswer']); for($i=0; $i &lt; count($question); $i++) { echo "POSTED ANSWERS" . $question[$i] . "&lt;br/&gt;"; } } else { echo '&lt;p style="color: Red"&gt;No Answers POSTED!&lt;/p&gt;'; } // loop 2 finds the comments if(isset($_POST['canswer'])){ ($comment = $_POST['canswer']); for($i=0; $i &lt; count($comment); $i++) { echo "POSTED COMMENTS" . $comment[$i] . "&lt;br/&gt;"; } } else { echo '&lt;p style="color: Red"&gt;No Comments POSTED!&lt;/p&gt;'; } // loop 3 combines the answers and comments for($x = 0; $x &lt; count($comment); $x++){ if(isset($question[$x])){ $question[$x] = $question[$x] . ' ' . $comment[$x]; } } $result = $question; // saves the answers and comments as a string ($result) </code></pre> <p>Each comment[$i] is the same key and $question[$i]. Inserting into the table i have:</p> <pre><code>$query = "INSERT INTO audit_data (Q4101, Q4102, Q4103, Q4104, etc...) VALUES '$result[0]','$result[1]','$result[2]','$result[3]','$result[4]', etc...)"; mysqli_query($link, $query) or die(mysqli_error($link)." Q=".$query); </code></pre> <p>1) is this the best way to go about this?</p> <p>2) It is nearly working, i can get the $question and $comment into the first columns for instance: $result[0] to result[10] but if i try to insert further on in the table say $result[40] to $result[50] i only get the $question values and no $comment values. </p> <p>I have looked at array_map and preg_match on the manual but not sure how or which one to use.</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.
    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