CodeIgniter Forums
passing variable in URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: passing variable in URL (/showthread.php?tid=19911)



passing variable in URL - El Forum - 06-22-2009

[eluser]agubski[/eluser]
Hi,

I'm sure this is very stupid question, but I kind of shamefully stuck here.

I need to insert a variable $city into a Anchor tag and I getting all kind of errors.

here is the string

Code:
&lt;?=anchor('index.php?/display_add/details', '<img src="images/find.gif" border="0" alt="">');?&gt;

I need variable $city to be passed as a URI segment after /details...

Thanks

Alex


passing variable in URL - El Forum - 06-22-2009

[eluser]tonanbarbarian[/eluser]
this depends on how you get the data
if you use
Code:
$this->uri->segment(n);
Then something like this
Code:
&lt;?=anchor('index.php?/display_add/details/'.$city, '<img src="images/find.gif" border="0" alt="">');?&gt;

If like me you prefere to make an array of segments using
Code:
$this->uri->uri_to_assoc(n);
then you would use something like
Code:
&lt;?=anchor('index.php?/display_add/details/city/'.$city, '<img src="images/find.gif" border="0" alt="">');?&gt;
then
Code:
$segments = $this->uri->uri_to_assoc(3);
would produce
Code:
$segments[array]
(
  'city'=>xyz,
)
I prefer this because the segments can then be added in any order of matching pairs and the url still works


passing variable in URL - El Forum - 06-22-2009

[eluser]TWP Marketing[/eluser]
Assuming you have the value in the variable $city, then this should pass that value back as segment 5. Don't forget the slash after the function name "details".

Code:
&lt;?=anchor('index.php?/display_add/details/'.$city, '<img src="images/find.gif" border="0" alt="">');?&gt;



passing variable in URL - El Forum - 06-22-2009

[eluser]agubski[/eluser]
Thanks a lot,

little dot made all the difference Smile