Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

How to make a text string into a bullet list

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

How to make a text string into a bullet list

Postby stockholmminora » Mon Apr 01, 2013 8:22 am

I have a multi-select box (with a list of countries) on my BuddyPress registration page and would like to display the results on a member's page in a bullet list.

Unfortunately, the code below still displays the text as a string.

Code: Select all
<?php
//string looks like this: "USA, Canada, Japan, Russia"
$countries = bp_member_profile_data( 'field=Countries' );

$array = explode(",", $countries);

if ( ! empty( $countries ) ) {
    echo '<ul>';
    foreach ( $array as $country ) {
        printf( '<li>%s</li>', $country );
    }
    echo '</ul>';
}
stockholmminora
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 01, 2013 8:19 am

Re: How to make a text string into a bullet list

Postby seandisanti » Mon Apr 01, 2013 8:42 am

$countries ='USA, Canada, Japan, Russia';
//string looks like this: "USA, Canada, Japan, Russia"
$array = explode(",", $countries);

if ( ! empty( $countries ) ) {
echo '<ul>';
foreach ( $array as $country ) {
echo '<li>' . $country . '</li>';
}
echo '</ul>';
}
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to make a text string into a bullet list

Postby stockholmminora » Mon Apr 01, 2013 10:21 am

What would come after "$countries =" since the results are being pulled from the database dynamically?

To show the results as a list, I use the following code...

Code: Select all
<?php bp_member_profile_data( 'field=Activities'); ?>


Thanks so much.
stockholmminora
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 01, 2013 8:19 am

Re: How to make a text string into a bullet list

Postby seandisanti » Mon Apr 01, 2013 10:24 am

I saw that, but i went with a literal string since i don't have access to that function, or your database. assuming your function call returns a comma delimited string as your comment implied, you should be able to just drop your function call back in there. if that doesn't work, then add: die($countries) right after that line to see what your function is actually returning.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to make a text string into a bullet list

Postby stockholmminora » Mon Apr 01, 2013 10:54 am

Thanks so much for your feedback. Sorry to be a pain, but when I use the following code:

$countries = 'bp_member_profile_data( 'field=Countries' );'

I get a syntax error.

Parse error: syntax error, unexpected T_VARIABLE in /home/content/59/9161159/html/wp-content/themes/parallelus-razor/members/single/profile/profile-loop.php on line 38
stockholmminora
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 01, 2013 8:19 am

Re: How to make a text string into a bullet list

Postby seandisanti » Mon Apr 01, 2013 10:59 am

usually that means you've missed a semi colon or you've got an unterminated string; at the end of the line before the one referenced. so probably on or around line 37 in /home/content/59/9161159/html/wp-content/themes/parallelus-razor/members/single/profile/profile-loop.php
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to make a text string into a bullet list

Postby stockholmminora » Mon Apr 01, 2013 11:39 am

Well, I'm stumped. When I use the code below, it still displays as a text string on one line.

Code: Select all
<?php
$countries = bp_member_profile_data('field=Countries');
$array = explode(",", $countries);

if ( ! empty( $countries ) ) {
echo '<ul>';
foreach ( $array as $country ) {
echo '<li>' . $country . '</li>';
}
echo '</ul>';
}
?>


Thanks for your help.
stockholmminora
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 01, 2013 8:19 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 10 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.