If Statement Question


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.

$i = 1;

               $query = $db->query( "SELECT * FROM played_songs ORDER BY times_played desc LIMIT 10" );
		while( $array = $db->assoc( $query ) ) {

$art = LastFM::getArtwork($array['artist'], $array['name'], true, "extralarge");

if ($art == "no") { $art = "<img class=\\"border-radius\\" src=\\"/images/pics/album_artwork.png\\" height=\\"206\\" width=\\"252\\" />"; }

                    <tr style="background: #f3f3f3;">

                        <td width="20%">
                            <center><?php echo $i; ?></center>

                        <td width="40%">
                            <center><?php echo $art; ?></center>

                        <td width="40%">
                            <center><?php echo $array['artist'] . "<br>-<br>" . $array['name']; ?><br><i>(Played <?php echo $array['times_played']; ?> times)</i></center>


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?

Many thanks,

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.

Thank you so much - that worked perfectly! Maybe you can help me out with something even more simple.

This page is the page that inserts it into the db, and after, is supposed to direct to another page. Here is the code:

$sql = "INSERT INTO oneshot (id,fname, lname, email) VALUES ('','$fname','$lname','$email')";
mysql_query($sql) or die('failed because '.mysql_error());
header("Location: thanks.php");

It won’t redirect to the thanks page, though… Any ideas why? Sorry - but thanks!

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.