1,105,363 Community Members

while loop unwanted

Member Avatar
CreatorZeus
Newbie Poster
22 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 ";
            }
        }
        ?>
Member Avatar
AARTI SHRIVAS
Posting Pro in Training
410 posts since Dec 2012
Reputation Points: 2 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 3 [?]
 
0
 
echo $result;

try this check out put of your query

Member Avatar
broj1
Posting Virtuoso
1,578 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
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.

Member Avatar
broj1
Posting Virtuoso
1,578 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
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.

Member Avatar
IIM
Master Poster
742 posts since Jun 2011
Reputation Points: 163 [?]
Q&As Helped to Solve: 169 [?]
Skill Endorsements: 24 [?]
 
0
 

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

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