premora Posted March 29, 2011 Share Posted March 29, 2011 Hello all, I am a real newby to this but need some help with a file_exists / while loop issue i have. I am trying to show a table of pictures (with their own ID's) but also if someone hasn't uploaded a picture to the server a default picture will be shown instead. I get the error: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/thefrien/public_html/members1.php on line 103 Here is my code: $i = 1; echo "<table border='1' align='center'><tr>"; $result = mysql_query( "SELECT * FROM membership order by L_ID asc" ); while ( $row = mysql_fetch_assoc( $result ) ) { echo "<td align='center' bgcolor='#DDDEFF'><a href='profile_view.php?L_ID=".$row["L_ID"] ."'>" $pic = 'images/avatar/'. $row["L_ID"] .'s.jpg'; if (file_exists($pic)) { echo '<img src=http://www.thefriendzconnection.co.uk/images/avatar/'.$row["L_ID"] ."s.jpg>"; } else { echo '<img src=http://www.thefriendzconnection.co.uk/images/0s.jpg border='0'>'; } "</a> <br><font size='1' face='Arial, Helvetica, sans-serif'>".$row["name"] ."</font> <br><font size='1' face='Arial, Helvetica, sans-serif'>ID: ".$row["L_ID"] ."</font> <br> </td>"; if ( $i % 6 == 0 ) { echo "</tr><tr>"; } $i++; } mysql_free_result( $result ); echo "</tr></table>"; The line I am having issues with seems to be: $pic = 'images/avatar/'. $row["L_ID"] .'s.jpg'; Any suggestions would be greatfully received Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/ Share on other sites More sharing options...
.josh Posted March 29, 2011 Share Posted March 29, 2011 improper use of quotes. echo '<img src=http://www.thefriendzconnection.co.uk/images/0s.jpg border='0'>' should be echo "<img src=http://www.thefriendzconnection.co.uk/images/0s.jpg border='0'>"; Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193646 Share on other sites More sharing options...
.josh Posted March 29, 2011 Share Posted March 29, 2011 missing semicolon: echo "<td align='center' bgcolor='#DDDEFF'><a href='profile_view.php?L_ID=".$row["L_ID"] ."'>" should be echo "<td align='center' bgcolor='#DDDEFF'><a href='profile_view.php?L_ID=".$row["L_ID"] ."'>"; Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193647 Share on other sites More sharing options...
.josh Posted March 29, 2011 Share Posted March 29, 2011 missing echo "</a> <br><font size='1' face='Arial, Helvetica, sans-serif'>".$row["name"] ."</font> <br><font size='1' face='Arial, Helvetica, sans-serif'>ID: ".$row["L_ID"] ."</font> <br> </td>"; should be echo "</a><br><font size='1' face='Arial, Helvetica, sans-serif'>".$row["name"] ."</font><br><font size='1' face='Arial, Helvetica, sans-serif'>ID: ".$row["L_ID"] ."</font><br> </td>"; Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193649 Share on other sites More sharing options...
premora Posted March 29, 2011 Author Share Posted March 29, 2011 Hi Crayon, Isn't the echo at the top covering this part of the code? I have just slotted in between the If statement. The first resolution returned the same error Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193650 Share on other sites More sharing options...
premora Posted March 29, 2011 Author Share Posted March 29, 2011 I tried adding the echo anyway and I still get the same error on that line: $pic = 'images/avatar/'.$row["L_ID"] .'s.jpg'; Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193651 Share on other sites More sharing options...
.josh Posted March 29, 2011 Share Posted March 29, 2011 No. echo doesn't work that way. You can't put if statements inside an echo like that. This is your code with the changes. $i = 1; echo "<table border='1' align='center'><tr>"; $result = mysql_query( "SELECT * FROM membership order by L_ID asc" ); while ( $row = mysql_fetch_assoc( $result ) ) { echo "<td align='center' bgcolor='#DDDEFF'><a href='profile_view.php?L_ID=".$row["L_ID"] ."'>"; $pic = 'images/avatar/'. $row["L_ID"] .'s.jpg'; if (file_exists($pic)) { echo '<img src=http://www.thefriendzconnection.co.uk/images/avatar/'.$row["L_ID"] ."s.jpg>"; } else { echo "<img src=http://www.thefriendzconnection.co.uk/images/0s.jpg border='0'>"; } echo "</a><br><font size='1' face='Arial, Helvetica, sans-serif'>".$row["name"] ."</font><br><font size='1' face='Arial, Helvetica, sans-serif'>ID:".$row["L_ID"] ."</font><br> </td>"; if ( $i % 6 == 0 ) { echo "</tr><tr>"; } $i++; } mysql_free_result( $result ); echo "</tr></table>"; Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193673 Share on other sites More sharing options...
premora Posted March 29, 2011 Author Share Posted March 29, 2011 Excellent - That got it. Really appreciate your time and thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/232049-error-when-using-file_exists-in-a-while-loop/#findComment-1193674 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.