0

I have the following php and sql code, it works perfectly is the user has at least one of the 4 cases in tblactions. The problem occurs if the user only has 1 of the cases, for example attending. Then it seems to go on an infinite loop and the page won't load. Can anyone help me alter this code?

 $result5 = mysql_query("SELECT tblactions.*, fgusers.username FROM tblactions LEFT JOIN fgusers ON fgusers.id_user = tblactions.following_id WHERE user_id = '$test' ORDER BY timestamp DESC")

    while ($row5 = mysql_fetch_array($result5))
    {
        $actiontype = $row5['type'];
        switch ($actiontype)
    {
    case "event":

       echo '<div id="peepme" class="ui-btn-text">',
            '<img id="peoplemeimg" alt="Happps" src="image/'.$row7['photo'].'" class="ui-li-thumb">',
            '<h3 id="pmh3" class="ui-li-heading">',$row5['user_name'], ' created the event','</h3>', 
            '<a id="pmevent" data-ajax="false" class="ui-li-heading" href="eventview.php?eventid='.$row5['event_id'].'">',$row5['event_name'],'</a>',

            '</div>';
       break;

    case "follow":

       echo '<div id="peepme" class="ui-btn-text">',
            '<img id="peoplemeimg" alt="Happps" src="image/'.$row7['photo'].'" class="ui-li-thumb">',
            '<h3 id="pmh3" class="ui-li-heading">',$row9['username'], ' started following','</h3>', 
            '<a id="pmevent" data-ajax="false" class="ui-li-heading" href="people.php?id='.$row5['following_id'].'">',$row5['username'],'</a>',

            '</div>';

       break;

    case "photo":

    echo '<div id="peepme" class="ui-btn-text">',
         '<img id="peoplemeimg" alt="Happps" src="image/'.$row7['photo'].'" class="ui-li-thumb">',
         '<h3 id="pmh3" class="ui-li-heading">',$row9['username'], ' uploaded a photo','</h3>', 
         '<div id="imgupld">','<img id="upldimg" alt="Happps" src="image/'.$row5['photo'].'" class="ui-li-thumb">',

         '</div>',                  
         '</div>';

       break;

    case "attending":

    echo '<div id="peepme" class="ui-btn-text">',

         '<img id="peoplemeimg" alt="Happps" src="image/'.$row7['photo'].'" class="ui-li-thumb">',
         '<h3 id="pmh3" class="ui-li-heading">',$row9['username'], ' is attending ','</h3>', 
         '<a id="pmevent" data-ajax="false" class="ui-li-heading" href="eventview.php?eventid='.$row5['event_id'].'">','This Event','</a>',

         '</div>';


        }?> 
4
  • 2
    You seem to be missing a closing brace for while Commented Feb 12, 2013 at 4:04
  • you also forget to add break at attending case... Commented Feb 12, 2013 at 4:12
  • @steven reda ,Dipesh Parmar and Explosion Pills is right , close brace for while is missing. Commented Feb 12, 2013 at 4:12
  • Can I also recommend the use of an abstraction layer like PDO Commented Feb 12, 2013 at 4:16

1 Answer 1

2

This is the error.

case "attending":

echo '<div id="peepme" class="ui-btn-text">',

        '<img id="peoplemeimg" alt="Happps" src="image/'.$row7['photo'].'" class="ui-li-thumb">',
        '<h3 id="pmh3" class="ui-li-heading">',$row9['username'], ' is attending ','</h3>', 
        '<a id="pmevent" data-ajax="false" class="ui-li-heading" href="eventview.php?eventid='.$row5['event_id'].'">','This Event','</a>',
    '</div>';

break;

Forget to break attending case.

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

3 Comments

nice catch ... well answer.
Thanks, guess I was looking at it too long.
It is interesting, as last case in switch does not need break statement. May be inside a loop had different behavior.

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.