2

I've written a php code to display all the images. But there's is something wrong in the code and I can't fix it. It's kind of a syntax error but I've wasted hours over it and still mixing up the "quotes(')"..here's my php code:

while($row = mysql_fetch_array($display_query)){
    print "<tr><td>".$row['itemid']."</td><td><img src="resources/wh/'.$row['itemid'].'.png"/></td><td>".$row['description']."</td><td>";
    print "&#8377;".$row['cost']."</td></tr>";
}
3
  • "something wrong " care to tell us what? Commented Jun 9, 2012 at 4:46
  • first check with firebug,is image is loading or not?if not try with one image and go for multiple images Commented Jun 9, 2012 at 4:49
  • while($row = mysql_fetch_array($display_query)){ echo "<tr><td>".$row['itemid']."</td><td>"; echo '<img src="resources/wh/'.$row['itemid'].'.png" title="'.$row['itemid'].'"/>'; echo "</td><td>".$row['description']."</td><td>"; echo "&#8377;".$row['cost']."</td></tr>"; } Commented Jun 9, 2012 at 4:57

4 Answers 4

4
"<tr><td>".$row['itemid']."</td><td><img src="resources/wh/'.$row['itemid'].'.png"/></td><td>".$row['description']."</td><td>";

Should be

"<tr><td>".$row['itemid'] . '</td><td><img src="resources/wh/'.$row['itemid'].'.png"/></td><td>'.$row['description']."</td><td>";

But mix ' and " make your code a mess, you could use HEREDOC to make it more readable.

while($row = mysql_fetch_array($display_query)){
  echo <<<EOF
<tr>
    <td>{$row['itemid']}</td>
    <td><img src="resources/wh/{$row['itemid']}.png"/></td>
    <td>{$row['description']}</td>
    <td>&#8377;{$row['cost']}</td>
</tr>
EOF;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Or, since he's using ", "<tr><td>{$row['itemid']}</td><td><img src='resources/wh/{$row['itemid']}.png'/></td><td>{$row['description']}</td><td>"; but yeah, HEREDOC is tidier. :)
I would point users to some explanation of HEREDOCs, as it's not something a new programmer will just run into - en.wikipedia.org/wiki/Here_document#PHP
2

Your concatenation of string and quotation is not right. Try this -

while($row = mysql_fetch_array($display_query)){
    print "<tr><td>" . $row['itemid']."</td><td><img src=" . 'resources/wh/' .$row['itemid']. ".png'/></td><td>".$row['description'] . "</td><td>";
    print "&#8377;".$row['cost']."</td></tr>";
}

2 Comments

Your concatenation of string and quotation is not right - you added an extra single-quote before the file extension, and for some reason separated the path into it's own string
Oh! it should be after the file extension. Thanks
1

The simplest solution is just make proper pencuation in your code.

The correct code is:

print "<tr><td>".$row['itemid']."</td><td><img src='resources/wh/".$row['itemid'].".png'/></td><td>".$row['description']."</td><td>";

Comments

0

from db we get column value of rating $number=$row->rating ;

if we want TO print image as rating value in a table row then then

 $number=$row->rating   ;   
 $middle="";
 $first="<td width='200' align='left'>";
  for($x=1;$x<=$number;$x++) {

   $middle=$middle.img($fullimage_properties);  
}


if (strpos($number,'.')) {
    $middle=$middle.img($halfimage_properties); 
    $x++;
}
while ($x<=5) {
    $middle=$middle.img($blankimage_properties);    ;
    $x++;
}


echo $last=$first.$middle."</td>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.