开发者

My While Loop is not grabbing the MySQL database entries

开发者 https://www.devze.com 2023-01-04 09:14 出处:网络
why isn\'t my while loop getting the mysql database entries and p开发者_如何学Pythonresenting them like demonstrated? Thanks :).

why isn't my while loop getting the mysql database entries and p开发者_如何学Pythonresenting them like demonstrated? Thanks :).

<?php $djs_all_db = mysql_query("SELECT * FROM djs")
        or die(mysql_error());      
        $djs_all_num = mysql_num_rows($djs_all_db);
        while($djs_all = mysql_fetch_array( $djs_all_db )) {
        if ($djs_all_num % "2") {
            echo "<div class=\"row\">
        <div class=\"column column-2\">
                <img src=\"images/about/" . $djs['username'] . "-profile.png\" alt=\"Profile\" class=\"profile-image\"/>

                <p class=\"float-left\"><strong>" . $djs['realname'] . "</strong></p>
                <p class=\"float-right\"><a href=\"#\" title=\"\">" . $djs['position'] . "</a></p>

                <div class=\"clear\"></div>

                <p>" . $djs['biography'] . "</p>

            </div>";
        } else {
            echo "<div class=\"column column-3\">
                <img src=\"images/about/" . $djs['username'] . "-profile.png\" alt=\"Profile\" class=\"profile-image\"/>

                <p class=\"float-left\"><strong>" . $djs['realname'] . "</strong></p>
                <p class=\"float-right\"><a href=\"#\" title=\"\">" . $djs['position'] . "</a></p>

                <div class=\"clear\"></div>

                <p>" . $djs['biography'] . "</p>

            </div></div>";
        } }?>


Your loop defines: $djs_all -- In your code you use: $djs['username'], change it to $djs_all['username']


Don't know if that's your issue, but

if ($djs_all_num % "2") { 

tests a static number( the number of entries in your table), so you'll always execute the if or the else part.

Also, you loop on a djsall variable:

while($djs_all = mysql_fetch_array( $djs_all_db )) {     

But you try to access fields from a $djs one:

<img src=\"images/about/" . $djs['username']
0

精彩评论

暂无评论...
验证码 换一张
取 消