1

I would like to be able to create a link using a variable (which changes depending on what is outputted from the a database). So if $name = dave, I would like to be able to say:

www.example.com/$name

which would be the same as:

www.example.com/dave

I have tried the following

foreach($query->result_array() as $row) {
    $name = $row['user_username'];
    echo anchor('User/view/$name', '$name'); 
}

but get the following error:

The URI you submitted has disallowed characters.

Thanks in advance for any help.

2 Answers 2

2

The variable shouldn't be in quotes:

echo anchor('User/view/'.$name, $name); 

should work.

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

1 Comment

But can be in double quote anchor("User/view/$name", $name);
2

If you do

www.example.com/dave 

It will go to a PHP page called dave, I dont think that is what you want.

To use variables in links you have to do something like this

www.example.com?name=dave

Also if you do

echo anchor('User/view/$name', '$name'); 

It will post '$name' and not what is in the var. Delete the single quotes: '...'

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.