-1

During a while loop in PHP I want to create following link:

echo '<a onclick="getSolution('.ResultArray['qid'].')" style="color: red;">L&ouml;sung anzeigen</a>';

But there it is a mistake. It will not take the $ResultArray['qid'] as a parameter for the javascript function. I need this parameter for define which div it has to take when clicking on the link.


Here you get the complete while loop in php:

while($ResultArray = mysqli_fetch_array($getQuestions)) {
    echo '<p>';
    echo $ResultArray['question'];
    echo '<br />';          
            echo '<input type="text" style="width: 500px;"/>';
    echo '</p>';
    echo '<a onclick="getSolution('.ResultArray['qid'].')" style="color: red;">L&ouml;sung anzeigen</a>';
    echo '<div id="'.$ResultArray['qid'].'" style="visibility: hidden">';
    echo $ResultArray['answer'];
    echo '</div>';
}

How I can fix this problem?

2 Answers2

3

You're trying to reference your ResultArray variable without prefacing it with your $ symbol.

Corrected:

echo '<a onclick="getSolution('.$ResultArray['qid'].')" style="color: red;">L&ouml;sung anzeigen</a>';
esqew
  • 42,425
  • 27
  • 92
  • 132
2
echo '<a onclick="getSolution('.ResultArray['qid'].')"
                                ^^^^^^^^^^^^---undefined constant, since it has no "$"

You must have $ResultArray in there. Without the $, it's a constant, and you cannot have constant arrays.

Marc B
  • 356,200
  • 43
  • 426
  • 500