0

Basically I've got a working drop-down menu php/mysql script running using the internet as my guide. But one thing I don't really understand is the significance of the period in

$options.
$sql = "SELECT DISTINCT artist FROM hits ORDER BY artist";
	$result = mysql_query($sql);
				
	while ($row=mysql_fetch_array($result)) { 
	
	    $artist=$row["artist"]; 
	    $options.="<option>$artist</option>"; 
	} 
	?>

I understand the rest etc but its just that one part that doesn't make sense to me, what does the "." do?!

Thanks

5
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by mschroeder
0

.= is for concatenate strings, ex:

$var = "Hi,";
$var .= "bye.";

This is the same as

$var = "Hi,";
$var = $var."bye.";

This will output: Hi,bye. .

1

As mentioned . is the concatenator. Your code however, could be quicker:

$sql = "SELECT DISTINCT artist FROM hits ORDER BY artist";
	$result = mysql_query($sql);
 
	while ($row=mysql_fetch_array($result)) {
	    $options.="<option>{$row['artist']}</option>"; 
	}

Also on some systems you'll need to set

$options = "";

before the while loop

Edited by diafol: n/a

0

As mentioned . is the concatenator. Your code however, could be quicker:

$sql = "SELECT DISTINCT artist FROM hits ORDER BY artist";
	$result = mysql_query($sql);
 
	while ($row=mysql_fetch_array($result)) {
	    $options.="<option>{$row['artist']}</option>"; 
	}

Also on some systems you'll need to set

$options = "";

before the while loop

One question: Why between {} ? I dont understand that...

0

When you enclose array variables, e.g. $array, you need to enclose them in braces {...}

I'm sure you know that this only works with double quotes. Single quotes will just spit out the literal string.

0

When you enclose array variables, e.g. $array, you need to enclose them in braces {...}

I'm sure you know that this only works with double quotes. Single quotes will just spit out the literal string.

I dont understand why between {}.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.