fife Posted February 16, 2011 Share Posted February 16, 2011 Hi im trying to echo out some html within php based on an if statement. Basically if you the is part of a club within a list item list the clubs, if they are not echo none within the list. Here is the code and below will be the error from the server. <?php // Query for finding out if the signed in user is part of any clubs and then display them here. $qMyClub = "SELECT clubID, name FROM clubs WHERE memberID = ".$User['memberID'].""; $rMyClub = mysql_query($qMyClub); $NumClubs = mysql_num_rows($rMyClub); if ($NumClubs>=1) { while($Clubs = mysql_fetch_assoc($rMyClub)){ echo"<li>My Clubs <ul> <li><a href=\"members/myclub.php?club='$Club['clubID']'\">$Club['name']</a></li> </ul> </li>"; } else ($NumClubs==0) { echo" <li>My Clubs <ul> <li>None</li> </ul> </li>"; } } ?> and the error; [error] [client ] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sites/index.php on line 78, referer: its referencing to the following line; <li><a href=\"members/myclub.php?club='$Club['clubID']'\">$Club['name']</a></li> I dont understand php enough to fix this can anyone help? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 16, 2011 Share Posted February 16, 2011 Enclose your array elements in curly braces: {$array['element']} Quote Link to comment Share on other sites More sharing options...
fife Posted February 16, 2011 Author Share Posted February 16, 2011 thank you but now the error has moved down a few lines; PHP Parse error: syntax error, unexpected T_ELSE in /home/sites/yourarena.co.uk/public_html/members/index.php on line 82, referer: // Query for finding out if the signed in user is part of any clubs and then display them here. $qMyClub = "SELECT clubID, name FROM clubs WHERE memberID = ".$User['memberID'].""; $rMyClub = mysql_query($qMyClub); $NumClubs = mysql_num_rows($rMyClub); if ($NumClubs>=1) { while($Clubs = mysql_fetch_assoc($rMyClub)){ echo"<li>My Clubs <ul> <li><a href=\"members/myclub.php?club='{$Club['clubID']}'\">{$Club['name']}</a></li> </ul> </li>"; } else ($NumClubs=0) { echo" <li>My Clubs <ul> <li>None</li> </ul> </li>"; } } it means this line else ($NumClubs==0) { I tried changing it to just one = but nothing Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 16, 2011 Share Posted February 16, 2011 Your while loop's closing curly brace seems to be missing, and it appears you're trying to use elseif() syntax with an else{}. Quote Link to comment Share on other sites More sharing options...
litebearer Posted February 16, 2011 Share Posted February 16, 2011 Perhaps... <?PHP // Query for finding out if the signed in user is part of any clubs and then display them here. $member_id = $User['memberID']; $qMyClub = "SELECT clubID, name FROM clubs WHERE memberID = $member_id'"; $rMyClub = mysql_query($qMyClub); $NumClubs = mysql_num_rows($rMyClub); if ($NumClubs>=1) { ?> My Clubs<br> <ul> <?PHP while($Clubs = mysql_fetch_assoc($rMyClub)){ ?> <li><a href="members/myclub.php?club=<?PHP echo $Club['clubID']; ?>"><PHP echo $Club['name']; ?></a></li> <?PHP } <?PHP </ul> <?PHP } }else{ ?> My Clubs<br> <ul> <li>None</li> </ul> <?PHP } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.