Jump to content

Error when using file_exists in a while loop


premora

Recommended Posts

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.

Link to comment
Share on other sites

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>"; 

Link to comment
Share on other sites

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>"; 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.