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

.= is for concatenate strings, ex:

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

This is the same as

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

This will output: Hi,bye. .

Member Avatar
diafol

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

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...

Member Avatar
diafol

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.

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 {}.