0

why isn't my while loop getting the mysql database entries and presenting 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>";
        } }?>
2
  • No error, unfortunately. Commented Jun 21, 2010 at 13:37
  • are you sure you meant if ($djs_all_num % "2") instead of if ($djs_all_num % 2==0)? $djs should be $djs_all Commented Jun 21, 2010 at 13:38

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.