1

I'm brand new to PHP and don't have the first clue about what I'm doing. I found the way to embed HTML in PHP by looking around this site.

However, I can't make this work. My code is:

<?php do { ?>
    <?php if ($row_rsMore['contentID'] = 35) : ?>
        <li><a href="aboutus.php"><h4><?php echo $row_rsMore['contentTitle']; ?></h4></a></li>
    <?php elseif ($row_rsMore['contentID'] = 37) : ?>
        <li><a href="contactus.php"><h4><?php echo $row_rsMore['contentTitle']; ?></h4></a></li>
    <?php elseif ($row_rsMore['contentID'] = 38) : ?>
        <li><a href="otherlinks.php"><h4><?php echo $row_rsMore['contentTitle']; ?></h4></a></li>
    <?php else : ?>
        <li><a href="more.php?idVal=<?php echo $row_rsMore['contentID']; ?>"><h4><?php echo $row_rsMore['contentTitle']; ?></h4></a></li>
    <?php endif ?>
<?php } while ($row_rsMore = mysql_fetch_assoc($rsMore)); ?>

I've tried surrounding the number (35, 37 and 38) with single quotes, double quotes, brackets and variations on these themes.

What happens is that the 'contentTitle' for each of the statements displays correctly but each href shows the same link (that of the first 'if' ie: 'aboutus.php').

What have I got wrong?

2
  • 1
    Comparisons should be done with == Commented Jan 11, 2017 at 12:26
  • You need to use == and not = in your if statements. Otherwise the first one will try to set a value and therefore be true. Commented Jan 11, 2017 at 12:28

1 Answer 1

3

try

if ($row_rsMore['contentID'] == 35) :

instead of single =

change all single = to ==

Sign up to request clarification or add additional context in comments.

1 Comment

For the love of... The one thing that never occurred to me to try. Many thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.