Jump to content

IF EOF then remove the ,?


jarv

Recommended Posts

hi, I have a list of keywords, is there a way of removing the ,(comma) at the end of the line?

Also how would i go about linking on the keywords?

 

while($row1 = mysql_fetch_array($result2))
      {
      $Keyword = $row1['keyword'];
  $KeywordID = $row1['keyword_id'];
       echo $Keyword;echo ', ';
       }

Link to comment
https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/
Share on other sites

Example:

 

<?php
$keyword_str = '';
while ($row1 = mysql_fetch_array($result2)) {
$keyword_str .= '<a href="keyword.php?id=' . $row1['keyword_id']; . '">' . $row1['keyword'] . '</a>, ';
}
echo substr($keyword_str, 0, -2);
?>

 

Will output comma (and space) separated links, linking to keyword.php?id=id_here

substr() removes the last comma and space from the string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.