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.

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"] ."'>";

 

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.