How to cleverly stop "while loop" (php)

Posted by user3735697 on Stack Overflow See other posts from Stack Overflow or by user3735697
Published on 2014-06-12T21:16:53Z Indexed on 2014/06/12 21:25 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

I'm having trouble with creating code that echoes a bunch of stuff that is corresponding to the mysql database row. It needs to keep creating the content until all rows are used and then stop.

But for some reason the php file causes the browser to keep loading (it never ends). Any help would be appreciated! Thanks!

<?php 

mysql_connect ("localhost", "root", "") or die ("We couldn't connect!");
mysql_select_db ("dr");
mysql_query ("SELECT * FROM songs");
$result = mysql_query ("SELECT * FROM songs");

while ($row=mysql_fetch_array($result)) {

    $name = $row ['songname'];
    $genres = $row ['songgenres'];
    $mediafire = $row ['mediafirelink'];
    $dropbox = $row ['dropboxlink'];
    $source = $row ['audiosource'];

    echo "
    <div class='playing'>
            <!-- ======== Song Name ======== -->
                <li class='songnameli' id='$source'>
                    <span class='info'>$name</span>
                    <audio>
                        <source src='music/singles/$source.mp3'>
                        <source src='music/singles/$source.ogg'>
                    </audio>
                </li>

            <!-- ======== Playlist ======== -->
                <li class='playlistli'>
                    <img src='icons/addtoplaylist.png' title='Add tot the playlist!' />
                </li>

            <!-- ======== Genres ======== -->
                <li class='genresli'>
                    <img src='icons/genres.png' title='Related genres' />
                    <span class='addedtext genres'>$genres</span>
                </li>

            <!-- ======== Social Media links ======== -->
                <li>
                    <span>
                    <img src='icons/share.png' alt='Share this with your friends!' title='Share this!'>
                    <!-- /// facebook /// -->
                        <a href='http://www.facebook.com/sharer.php?u=http://www.declassified-recordings.com'
                           class='addedtext nlink'
                           target='blank_'
                           onclick='popup (this.href, 800, 500); return false'>Facebook
                        </a>

                    <span>/</span>

                    <!-- /// Twitter /// -->
                        <a href='http://twitter.com/share?
                            text=Thank%20you%20For%20Sharing!%20It%20means%20the%20world%20to%20us!%40Declassifi3d%20
                            &url=http://www.declassified-recordings.com'
                           class='twitterlink nlink'
                           target='blank_'
                           onclick='popup (this.href, 800, 500); return false'>Twitter</a>


                    </span>

                </li>

            <!-- ======== Download links ======== -->

                <li>
                    <img src='icons/download.png' title='Download!'  />
                    <span>
                        <!-- /// Mediafire /// -->
                            <a href='$mediafire'
                               class='addedtext nlink'
                               target='_blank'>Mediafire</a>

                        <span class='genres'>/</span>

                        <!-- /// Dropbox /// -->
                            <a href='$mediafire'
                               class='twitterlink nlink'
                               target='_blank'>Dropbox</a>


                    </span>
                </li>
    </div>";
}
mysql_close ();
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql