Start New Discussion within our Web Development Community

My while keeps looping and i dont know why: code

        <?php
        $result = mysql_query("SELECT * FROM tag WHERE point='$pagename'");
        while($row = mysql_fetch_array($result))
        {
            $result = mysql_query("SELECT * FROM tag WHERE point='$pagename'");
            //username
            echo $row["user"] . " ||";
            //alias check
            $result = mysql_query("SELECT * FROM tag WHERE (user='$my_name' && point='$pagename')");
            if (!$row["alias"])
            {
                echo "As \"" . $my_name . "\"||";
            }
            else
            {
                echo "As \"" . $row["alias"] . "\"||";
            }

            switch ($row["role"])
            {
            case 1:
              echo "Author ||";
              break;
            case 2:
              echo "Illustrator ||";
              break;
            case 3:
              echo "Reader ||";
              break;
            default:
              echo "All ";
            }
        }
        ?>

On line 5 you are assigning the same value to $result over and over again.

$result = mysql_query("SELECT * FROM tag WHERE point='$pagename'");

so while($row = mysql_fetch_array($result)) condition is always true (it is always first row of the table). I would remove line 5.

The $result on line 9n is also causing trouble. What is the goal here? Maybe you post the database structure.

Comments
Nice pin point

Just a note on quoting strings. It has nothing to do with the error you are getting, just a suggestion. Instead of:

echo "As \"" . $row["alias"] . "\"||";

you can do either:

echo "As \"{$row["alias"]}\"||";

or

echo 'As "' . $row["alias"] . '"||';

It is slightly more readable and easier to debug. But it is your choice what you prefer.

This question has already been answered. Start a new discussion instead.