Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to print a comma-separated entry

Guest
Jan 05, 2010 Jan 05, 2010

I would like to print a comma-separated entry into separated entries:

Like when I put like <?php echo $row_rsContent['artists']; ?> I get: "Picasso,Chagall,Matisse" but I want it like "Picasso<br>Chagall<br>Matisse".

And also I want to link "Picasso" to another website.

Thanks for any furthre help.

TOPICS
Server side applications
729
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 05, 2010 Jan 05, 2010

Pass your variable to explode() to turn it into an array. Then do what you want with each element.

$artists = explode(',', $row_rsContent['artists']);

echo '<a href="link">' . $artists[0] . </a><br>';

echo $artists[1]. '<br>' . $artists[2] . '<br>';

Translate
LEGEND ,
Jan 05, 2010 Jan 05, 2010

Pass your variable to explode() to turn it into an array. Then do what you want with each element.

$artists = explode(',', $row_rsContent['artists']);

echo '<a href="link">' . $artists[0] . </a><br>';

echo $artists[1]. '<br>' . $artists[2] . '<br>';

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 06, 2010 Jan 06, 2010

Thanks a lot again.
I put like that (see below) .. because I have maybe even 10 or more "artists" I wonder if there is a possibility to do this in a kind of "repeated region"?

   <?php $artists = explode(',', $row_rsContent['nameArtist']); ?>
   <a href="artist2.php?cat=<?php echo $row_rsContent['casco_cat_id']; ?>&artist=<?php echo $artists[0]; ?>"><?php echo $artists[0]; ?></a><br>
   <a href="artist2.php?cat=<?php echo $row_rsContent['casco_cat_id']; ?>&artist=<?php echo $artists[1]; ?>"><?php echo $artists[1]; ?></a><br>
   <a href="artist2.php?cat=<?php echo $row_rsContent['casco_cat_id']; ?>&artist=<?php echo $artists[2]; ?>"><?php echo $artists[2]; ?></a><br>
   <a href="artist2.php?cat=<?php echo $row_rsContent['casco_cat_id']; ?>&artist=<?php echo $artists[3]; ?>"><?php echo $artists[3]; ?></a><br>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 06, 2010 Jan 06, 2010
LATEST

Oh, you want them all in links? That makes it a lot easier. Your original message said just the first one would be in a link. The following should do it:

<?php $artists = explode(',', $row_rsContent['nameArtist']);
  foreach($artists as $artist) { ?>
   <a href="artist2.php?cat=<?php echo $row_rsContent['casco_cat_id']; ?>&artist=<?php echo $artist; ?>"><?php echo $artist; ?></a><br>
<?php } ?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines