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

Member Avatar for P0lT10n

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

Member Avatar for P0lT10n

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

Member Avatar for P0lT10n

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.