php - Foreach in middle of return statement -


i'm working on tagging system image site, , have:

function formatimage($url, $description, $tags){  if(empty($description)){      $description = "<i>no description avaliable.</i>";  }  $tags = array("one", "two"); $added = "may 23, 2011";  return '     <div id="single" class="image">         <div id="image">             <img src="'.$url.'" />         </div>     </div>      <div id="meta">          <dl>             <dt>description</dt>              <dd>'.$description.'</dd>             <dt>added on</dt>             <dd>'.$added.'</dd>             <dt>tagged</dt>             <dd id="tags">'.                 foreach($tags $tag){                     return '<a href="/tagged/'.$tag.'">'.$tag.'</a>;                 }                 .'             </dd>         </dl>      </div>'; 

and farther down in functions.php:

function pullimage($id){      dbcon();      $sql = "select * images id='$id'";     $result = mysql_query($sql);     $row = mysql_fetch_assoc($result);      $url = $row['url'];     $description = $row['description'];      //tags     $sql = "select * tags itemid='$id'";     $result = mysql_query($sql);      $tags = array();              while($row = mysql_fetch_assoc($result)){          array_push($tags, $row['tag']);      }      //$tags = $tags;      $image = formatimage($url, $description, $tags);      echo $image;  } 

and problem have foreach inside return statement of format function. i'm confused how make work. how 1 go function inside return?

put foreach earlier in code:

$taglist = array(); foreach($tags $tag){     $taglist[] = '<a href="/tagged/'.$tag.'">'.$tag.'</a>'; } return '     <div id="single" class="image">         <div id="image">             <img src="'.$url.'" />         </div>     </div>      <div id="meta">         <dl>             <dt>description</dt>              <dd>'.$description.'</dd>             <dt>added on</dt>             <dd>'.$added.'</dd>             <dt>tagged</dt>             <dd id="tags">'.implode(', ', $taglist).'</dd>         </dl>     </div>'; 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -