1.11M Members

while loop unwanted

 
0
 

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 ";
            }
        }
        ?>
 
0
 
echo $result;

try this check out put of your query

 
1
 

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.

 
0
 

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.

 
0
 

Just remove line 5 as suggested by Broj1 then it will work fine.

Question Answered as of 1 Year Ago by broj1, IIM and AARTI SHRIVAS
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: