ryandward Posted April 8, 2011 Share Posted April 8, 2011 [Edit: Sorry I found my answer by searching for "period", then finding out that it is a string operator, then read about that. Doesn't seem easy to search for ".=" in Google. Thanks] I got some help here earlier, and I can pretty much understand everything, except I don't understand why there is $recordOptions .= "<option value=\"{$row['id']}\">"; $recordOptions .= " {$row['firstname']} {$row['lastname']}, {$row['gender']}, {$row['dob']}"; $recordOptions .= "</option>\n"; Why does this whole thing break without .= ? I am new to PHP so, sorry if the answer is really obvious. $recordOptions = ''; $query = "SELECT * FROM people"; $result = mysql_query($query); if(!$result) { $recordOptions = "<option>Error Retrieving Records</option>\n";; } else { while($row=mysql_fetch_assoc($result)) { $recordOptions .= "<option value=\"{$row['id']}\">"; $recordOptions .= " {$row['firstname']} {$row['lastname']}, {$row['gender']}, {$row['dob']}"; $recordOptions .= "</option>\n"; } } ?> <html> <body> <?php echo $confirmMsg; ?><br /> <form action ='' method='post'> Quote Link to comment https://forums.phpfreaks.com/topic/233036-someone-explain-in-this-context-solved/ Share on other sites More sharing options...
drisate Posted April 8, 2011 Share Posted April 8, 2011 It means concatenating assignment operator http://us2.php.net/manual/en/language.operators.string.php In english, the "dot" glues 2 strings into 1 $var .="Hello "; $var .="How are you."; echo $var; will print out "Hello How are you." Quote Link to comment https://forums.phpfreaks.com/topic/233036-someone-explain-in-this-context-solved/#findComment-1198525 Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 The .= operator basically appends the contents of the right side to the variable, so it'd be the same as doing this: while($row=mysql_fetch_assoc($result)) { $recordOptions = $recordOptions."<option value=\"{$row['id']}\">"; $recordOptions = $recordOptions." {$row['firstname']} {$row['lastname']}, {$row['gender']}, {$row['dob']}"; $recordOptions = $recordOptions."</option>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/233036-someone-explain-in-this-context-solved/#findComment-1198526 Share on other sites More sharing options...
ryandward Posted April 8, 2011 Author Share Posted April 8, 2011 The .= operator basically appends the contents of the right side to the variable, so it'd be the same as doing this: while($row=mysql_fetch_assoc($result)) { $recordOptions = $recordOptions."<option value=\"{$row['id']}\">"; $recordOptions = $recordOptions." {$row['firstname']} {$row['lastname']}, {$row['gender']}, {$row['dob']}"; $recordOptions = $recordOptions."</option>\n"; } Omg this is exactly what I needed. Thank you very much! I didn't know that it was cumulative. Quote Link to comment https://forums.phpfreaks.com/topic/233036-someone-explain-in-this-context-solved/#findComment-1198527 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.