Forum Moderators: coopster
I obviousley only want the artist to appear once in the "Artist" combobox so I need to check to see if the artist already exists. if it does then i don't add it again.
EG
echo '<select name="MyJukeBox" onchange="PopulateTracks(this)"><option value="">Select Artist</option>';
while ($row = mysql_fetch_array($result)) {
.NET Equiv --> If MyJukebox.Items.Contains($row['Artist'])=False then
echo '<option value="',$row['File Name'],'">',$row['Artist'],'</option>';
.NET Equiv --> End if
}
echo '</select>';
It's the PHP Equivelant of the .NET IF statement that I am stuck with...
Any Ideas? THank You in Advance.
Solvo
while ($row = mysql_fetch_array($result)) {
$ThisArtist=$row['Artist'];
If (!in_array($ThisArtist, $MyArtists)) {
echo '<option value="',$row['File Name'],'">',$row['Artist'],'</option>';
$ACount=count($MyArtists);
$ACount++;
$MyArtists[$ACount]=$row['Artist'];
}
}
$query = "select distinct Artist, FileName from music order by Artist";
So for the purpose of leaning the above query does the following.
1. We are only querying Columns "Artist" and "FileName" (select distinct Artist, FileName)
2. From the database "Music" (from music)
3. Ensuring that "Artist" is Distict (order by Artist). e.g. If I changed "order by Artist" to "order by FileName" would that prevent duplicate file names?
I started PHP about a week ago, now I'ts time to get a big fat book I think.
Again Thank You RocknBill.
Oh dear, I really need to get myself some kind of reference material don't I?
Understand that PHP and mySQL are not tied as one technology; I access mySQL from Perl, PHP, and as a stand-alone app. The efficiency of your PHP application is going to rely on the efficiency of how you are accessing mySQL. So if you want a good reference, it is here:
mySQL Documentation [dev.mysql.com]
... the above query does the following.
1 and 2, correct. 3, no.
The "order by" and direction clause can be applied to any valid field and has no effect on the select itself. The default without order by is order asc (ascending) by the auto increment column. With a column 1,2,3,4,5 as rows, no order clause and "order by id asc" are synonymous. "order by id desc" will give you 5,4,3,2,1.
Order by's on text fields order alphabetically. So!
If I changed "order by Artist" to "order by FileName" would that prevent duplicate file names?
No. It would just rearrange the results.
If you have duplicate file names, you may have bigger issues, but to answer the question,
$query = "select distinct FileName Artist, from music order by Artist";
If both fields have duplicates on different records, hmm . . . don't know . . . I'd re-think my logic.