I have a two dimensional array in PHP that prints the index of the array instead of the value.
Here’s where I set up the array.
for($i = 1;$i <= $numOfCriteria;$i++)
{
for($j = 1;$j <= $numOfScores;$j++)
{
$description[$i][$j] = mysql_real_escape_string($_POST['descriptionPosition'.$i.$j]);
}
}
Here’s the SQL query.
for($i = 1;$i <= $numOfCriteria;$i++)
{
for($j = 1;$j <= $numOfScores;$j++)
{
$this->Instructor->query("INSERT INTO Criteria_Description (description,CriteriaID,ScoreID) VALUES (\"$description[$i][$j]\",\"$criteriaID[$i]\", \"$scoreID[$j]\")");
}
}
This is what it puts in the database.
Array[1]
Array[2]
Array[1]
Array[2]
Thanks for any replies in advance.
That is because the parser of PHP doesn’t recognize multiple array indexes inside your string correctly.
If you try this:
You’ll realize:
To fix this, as illustrated above, use the
"{$var}"syntax. The curly braces around your variable expression ensure that the parser handles it correctly: