Problem with PHP strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ZeroFear
Forum Newbie
Posts: 14
Joined: Tue Feb 14, 2006 10:47 pm

Problem with PHP strings

Post by ZeroFear »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i have the following code

Code: Select all

$query = "SELECT name FROM roles";
		$result = mysql_query( $query );
		$num_rows = mysql_num_rows( $result );
		for ( $i=0; $i < $num_rows; $i++ ) {
			$tempName = mysql_result( $result, $i );
			// check $_POST if it contains the current role
			if ( !empty( $_POST[$tempName] ) ) {
				$roleString += $tempName.",";
			}
		}
roleString keeps coming out to be 0. i am collecting several dfferent strings from the database in this forloop, changing the value of tempName each time it loops, as you can see. I want the roleString to add the value of tempName to it if the IF statement checks out ok.

Is the += in PHP different from the one in Java or C++ when it comes to strings??


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ZeroFear wrote:Is the += in PHP different from the one in Java or C++ when it comes to strings??
No, it is not. += is a math operator in PHP. You want .=, a concatenation operator.
Post Reply