whats wrong with this line of code?

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

PHP Code: [ Select ]
echo "<TR><TD>" . "<img src=/"$row["image"]"/></img>" . "</TD></TR><TR><TD>" . $row['username'] . "</TD></TR>\n";


im getting the following error..

Quote:
Parse error: parse error, expecting `','' or `';'' in /home/virtual/site2/fst/var/www/html/members.php on line 16
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

You did not escape all the quotes between echo. Try something like this:
PHP Code: [ Select ]
echo "<TR><TD>" . "<img src=\"$row[image] \"/></img>" . "</TD></TR><TR><TD>" . $row['username'] . "</TD></TR>\n";
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

thanks very much, that did the trick...
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

Change it all to:

Code: [ Select ]
echo '<tr><td><img src="' . $row[image] . '" /></td></tr><tr><td>' . $row['username'] . '</td></tr>';


Best to use lowercase html.
Best to use single quotes instead of double on the parts that php doesn't need to parse.
There's no such thing as an </img> tag.
And you're better off without the linebreak at the end for optimization purposes.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

thanks for that tip, it will stop me from getting to these annoying errors now.

Now, when i preview my data dont show in 2 columns and go in rows... instead it goes down in 1 row.

preview: http://www.69kilobytes.co.uk/members.php

script:
PHP Code: [ Select ]
 
<? include("header.php"); ?>
 
<?
 
$columns = 2;
 
 
 
include('connect.php');
 
$query = "SELECT * FROM members ORDER BY id DESC";
 
$result = mysql_query($query);
 
$num_rows = mysql_num_rows($result);
 
echo "<TABLE BORDER=\"0\">\n";
 
for($i = 0; $i < $num_rows; $i++) {
 
    $row = mysql_fetch_array($result);
 
    if($i % $columns == 1) {
 
      echo "<TR>\n";
 
    }
 
   
 
    echo '<tr><td><img src="' . $row[image]  . '" /></td></tr><tr><td>' . $row['username'] . '</td></tr>';
 
    if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
 
        //if there is a remainder of 1, end the row
 
        //or if there is nothing left in our result set, end the row
 
        echo "</TR>\n";
 
    }
 
}
 
echo "</TABLE>\n";
 
?>
 
<? include("footer.php");?>
 
 
  1.  
  2. <? include("header.php"); ?>
  3.  
  4. <?
  5.  
  6. $columns = 2;
  7.  
  8.  
  9.  
  10. include('connect.php');
  11.  
  12. $query = "SELECT * FROM members ORDER BY id DESC";
  13.  
  14. $result = mysql_query($query);
  15.  
  16. $num_rows = mysql_num_rows($result);
  17.  
  18. echo "<TABLE BORDER=\"0\">\n";
  19.  
  20. for($i = 0; $i < $num_rows; $i++) {
  21.  
  22.     $row = mysql_fetch_array($result);
  23.  
  24.     if($i % $columns == 1) {
  25.  
  26.       echo "<TR>\n";
  27.  
  28.     }
  29.  
  30.    
  31.  
  32.     echo '<tr><td><img src="' . $row[image]  . '" /></td></tr><tr><td>' . $row['username'] . '</td></tr>';
  33.  
  34.     if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
  35.  
  36.         //if there is a remainder of 1, end the row
  37.  
  38.         //or if there is nothing left in our result set, end the row
  39.  
  40.         echo "</TR>\n";
  41.  
  42.     }
  43.  
  44. }
  45.  
  46. echo "</TABLE>\n";
  47.  
  48. ?>
  49.  
  50. <? include("footer.php");?>
  51.  
  52.  


Tables seem to be fine to me, its when i preview it when i get :S confused.

Anyone is free to this script after just like the others on the other posts.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 147 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.