0

I need help with this. I'm passing two variable through a html link as shown below :

<?php
//loop through the array
foreach ($precost1 as $value): ?>
<ul><li><a name="farmname" href="<?php echo base_url().'uploads/farms/'.$farm;'/'.$value->farmcycle;?>"><?php echo $value->cyclename;?></a></li></ul>
<?php endforeach; ?>

But the link is not working as expected, it ignores the second variable $value->farmcycle any help with the right syntax please?

5 Answers 5

1

.$farm;'/'

The semicolon closes the line, try using . instead.

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

Comments

1

semicolon ends php statement, use .(dot) as concat operator

foreach ($precost1 as $value) {
  echo '<ul><li><a name="farmname" href="'.base_url().'uploads/farms/'.$farm.'/'.$value->farmcycle.'">'.$value->cyclename.'</a></li></ul>';    
}

Comments

1

After $farm you had a ; and forgot to concatentate .

<ul><li><a name="farmname" href="<?php echo base_url().'uploads/farms/'.$farm .'/'.$value->farmcycle;?>"><?php echo $value->cyclename;?></a></li></ul>

Comments

1

Try this

<?php
//loop through a list of farmnames and create link for each listed farmname
foreach ($precost1 as $value): ?>
    <ul><li><a name="farmname" href="<?php echo base_url().'uploads/farms/'.$farm.'/'.$value->farmcycle;?>"><?php echo $value->cyclename;?></a></li></ul>

<?php endforeach?>

Comments

0

Also, are you sure you want to be creating a <ul> tag for each new item?

Try putting this outside of the foreach, so you are just creating a <li> for each item.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.