variable string inside fixed string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

variable string inside fixed string

Post by Richard_in_Az »

Code: Select all


<?php
$rel="rel=";
for ($i=1; $i<=2; $i++){
 echo "<li><a href='#' rel='country1' class='selected'>$pic[$i]</a></li>";
}
?>

Problem: How do I make it so that during the loop, $i is added to "country"?
So that the html output will show "country1", "country2", "country3" etc etc.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: variable string inside fixed string

Post by requinix »

I see you already know how to put variables in strings. So what don't you understand?

Stick the variable right in there just like as you did with $pic.
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Re: variable string inside fixed string

Post by Richard_in_Az »

As they say in Missouri, show me. I have tried various combinations and nothing works for me.
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Re: variable string inside fixed string

Post by Richard_in_Az »

Code: Select all

<?php
$link="<a href='#' rel='country'";
for ($i=2; $i<=2; $i++){
  $link.=$i.">";
 echo "<li>$link $pic[$i]</a></li>";
}
?>

Ok so I worked out this. Now the problem is, the "country" is supposed to be passed on to the next part of the code as a unique id.
But that isn't happening. As in

Code: Select all

<div id="country1" class="tabcontent"> 
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Re: variable string inside fixed string solved

Post by Richard_in_Az »

Code: Select all

<?php

for ($i=2; $i<=2; $i++){
   echo "<li><a href='#' rel = country$i>";
   echo "$pic[$i]</a></li>";
}
?>
Post Reply