I am currently writing a dummy comment/answer system using PHP/SQL/AJAX and have come an issue on my output divs due to my coding style syntax.
To simplify the code I have just included the while loop: //prep query $sqlQuery = "SELECT * FROM Questions ORDER BY QuestionID DESC";
//exec query
$result = mysql_query($sqlQuery) or die(mysql_error());
//loop for multipule results
while ($row = mysql_fetch_array($result))
{
echo '<div class="test" id="test_$questionID">'; //<--doesn't work
//code here
echo '</div>';
echo "<div class='test' id='test_$questionID'>"; //<--works
//code here
echo '</div>';
}
Output of failed code line:
<div class="test" id="test_$questionID">
Output of successful code line:
<div class='test' id='test_21'>
The code above works when I start an echo using " instead of ' my PHP style is to start each outer with ' and innners with ".
Should I change my div echos to start with " or is there another way?
Edit: Thanks for all the quick replies all!
I was taught to start using singles instead of doubles without the actual reason behind it.
I didn't know the conflict was caused because of the text being interpreted incorrectly and the environment wasn't throwing any errors to guide. Escaping them as @PressingOnAlways or changing them as @santhy recommend.
It's not that I was asking the difference between singles and doubles since I didn't know that was the area of error. I can see now that it was, but not sure I would have know to look for that stack article first sorry.