jarv Posted June 27, 2008 Share Posted June 27, 2008 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 ', '; } Quote Link to comment https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/ Share on other sites More sharing options...
Jabop Posted June 27, 2008 Share Posted June 27, 2008 <?php $var=substr($var,0,-2); ?> You can link stuff using the a href html tag. Quote Link to comment https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/#findComment-575953 Share on other sites More sharing options...
thebadbad Posted June 27, 2008 Share Posted June 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/#findComment-575967 Share on other sites More sharing options...
jarv Posted June 27, 2008 Author Share Posted June 27, 2008 sorry I don't understand $var=substr($var,0,-2); Quote Link to comment https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/#findComment-575975 Share on other sites More sharing options...
thebadbad Posted June 27, 2008 Share Posted June 27, 2008 substr() returns a part of a string. substr($var, 0, -2) returns the string $var 2 characters shorter (cutted from the end). It's free to check the manual, you know? Quote Link to comment https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/#findComment-575992 Share on other sites More sharing options...
sasa Posted June 27, 2008 Share Posted June 27, 2008 try <?php $start = true; while($row1 = mysql_fetch_array($result2)) { $Keyword = $row1['keyword']; $KeywordID = $row1['keyword_id']; if ($start) $start = false; else echo ', ';echo $Keyword; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112199-if-eof-then-remove-the/#findComment-576191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.