SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If Statement Question

    All,

    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.

    PHP Code:
           <?php
    $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>

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

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


                        </tr>
    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,
    Bobby

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by boboreo
    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.

    PHP Code:
    $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.
    The only code I hate more than my own is everyone else's.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    PHP 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");
    exit; 
    It won't redirect to the thanks page, though.. Any ideas why? Sorry - but thanks!

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    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.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •