CSS id+ inside PHP tags

I have this…

echo "<div id="dave"><h2>" . $row['title'] . "<br /></b></h2>";
    echo "<p>" .$row['description'] . "<br /></p>";
    echo "<p><b>Step 1:</b> " .$row['step1'] . "<br /></p>";
    echo "<p><b>Step 2:</b> " .$row['step2'] . "<br /></p>";
    echo "<p><b>Step 3:</b> " .$row['step3'] . "<br /></p>";
    echo "<p><b>Step 4:</b> " .$row['step4'] . "<br /></p>";
    echo "<p><b>Step 5:</b> " .$row['step5'] . "<br /></p>";
    echo "<p><b>Step 6:</b> " .$row['step6'] . "<br /></p>";
    echo "<p><b>Step 7:</b> " .$row['step7'] . "<br /></p>";
    echo "<p><b>Step 8:</b> " .$row['step8'] . "<br /></p>";
    echo "<p><b>Step 9:</b> " .$row['step9'] . "<br /></p>";
    echo "<p><b>Step 10:</b> " .$row['step10'] . "<br /></p>";
    echo "<p><b>Category:</b> " .$row['maincat'] . "<br /></p>";   
    echo "<p>" ."<img src='images/".$row['image1']. "' /><br /></p></div>";

Which breaks due to this bit

<div id="dave">

It gives this error…

Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/fhlinux009/n/niallomeara.co.uk/user/htdocs/gallery/index.php on line 47

Can I not use CSS id’s inside PHP tags?

Or, you can skip all that string and escaping non-sense and selectively drop in/out of PHP like so. :wink:


<?php while($row = mysql_fetch_assoc($result)): ?>
  <div id="dave">
    <p><strong>Step 1:</strong><br /><?php echo $row['step1']; ?></p>
    <p><strong>Step 2:</strong><br /><?php echo $row['step2']; ?></p>
    <p><strong>Step 3:</strong><br /><?php echo $row['step3']; ?></p>
    <p><strong>Step 4:</strong><br /><?php echo $row['step4']; ?></p>
    <p><strong>Step 5:</strong><br /><?php echo $row['step5']; ?></p>
    <p><strong>Step 6:</strong><br /><?php echo $row['step6']; ?></p>
    <p><strong>Step 7:</strong><br /><?php echo $row['step7']; ?></p>
    <p><strong>Step 8:</strong><br /><?php echo $row['step8']; ?></p>
    <p><strong>Step 9:</strong><br /><?php echo $row['step9']; ?></p>
    <p><strong>Step 10:</strong><br /><?php echo $row['step10']; ?></p>        
  </div>
<?php endwhile; ?>


Note:
Uses PHP’s alternative syntax.

You can, but you have to escape them w/ backslashes, i.e.


echo "<div class=\\"dave\\">";

or use single quotes for the string:


echo '<div class="dave">';

:slight_smile:

Brilliant thank you so much.