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: <?=anchor('index.php?/display_add/details', '<img src="images/find.gif" border="0" alt="">');?> 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); Code: <?=anchor('index.php?/display_add/details/'.$city, '<img src="images/find.gif" border="0" alt="">');?> If like me you prefere to make an array of segments using Code: $this->uri->uri_to_assoc(n); Code: <?=anchor('index.php?/display_add/details/city/'.$city, '<img src="images/find.gif" border="0" alt="">');?> Code: $segments = $this->uri->uri_to_assoc(3); Code: $segments[array] 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: <?=anchor('index.php?/display_add/details/'.$city, '<img src="images/find.gif" border="0" alt="">');?> passing variable in URL - El Forum - 06-22-2009 [eluser]agubski[/eluser] Thanks a lot, little dot made all the difference |