After horrendous head trauma that I sustained, I am having to relearn PHP, and it stinks - it is so much harder than it was before. This is a really easy question, I think.
The code, as you can see, grabs the played songs from the database. I just want to make it so that if it has “Backing” or “Backing Track” or “Fly_” in the title, it doesn’t play it - because it is backing tracks for an online radio station.
How do I do that? It’s an if statement, I do believe… Can you all provide guidance?
Actually, even more simple than that. Merely exclude the rows from the query result itself using conditions to filter results via a where clause.
$query = $db->query( "SELECT * FROM played_songs WHERE name NOT LIKE '%Backing%' AND name NOT LIKE '%Backing Track%' AND name NOT LIKE '%Fly_%' ORDER BY times_played desc LIMIT 10" );
// - $query = $db->query( "SELECT * FROM played_songs ORDER BY times_played desc LIMIT 10" );
There might be a more optimized where by which to do the same thing though the method I posted is the one that immediately comes to mind. You can look up some string comparison functions in MySQL or ask in the SQL forum for that.
I will also add that I don’t quite understand what a “backing track” is but would argue that either a separate column or table should be used for keeping track of that data, rather than embedding it within the title. Embedding data within the title that changes an applications behavior breaks first normal form. You shouldn’t be storing four separate pieces of data in a single column which seems to be what is happening. That said it might not be changeable but if it is I would rethink that. If you were to store the data in a separate table or perhaps columns(s) the query could be more optimized and prepared to use joins. If joins are ever required with other tables the significance of having the data in a separate table or columns is going to become increasingly more evident considering the limited options to optimize using indexes.