Reputation: 942
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.
Upvotes: 1
Views: 340
Reputation: 2581
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: '...'
Upvotes: 2
Reputation: 7715
The variable shouldn't be in quotes:
echo anchor('User/view/'.$name, $name);
should work.
Upvotes: 2