开发者

simple Echo Error

i try to make a while{ part in php, to read out a mysql db. Works perfectly, only with the output i have problems:

echo "<div id=\"content\"><ul class=\"pageitem\"><li class=\"store\"><a href=\"index.html\"><span class=\"image\" style=\"background-image: url('<?php echo \". $zeile['image'] . \"; ?>')\"></span><span class=\"name\"><?php echo \". $zeile['title'] . \"; ?></span><span class=\"arrow\"></span></a></li></ul>";

Error is:

Pars开发者_高级运维e error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\xampplite\htdocs\harti\products.php on line 40

Sry i'm really new with php, i think this is a simple mistake but cannot find it.

thx for help


Don't use <?php again...

echo "<div id=\"content\"><ul class=\"pageitem\"><li class=\"store\"><a href=\"index.html\"><span class=\"image\" style=\"background-image: url('". $zeile['image'] . "')\"></span><span class=\"name\">". $zeile['title'] . "</span><span class=\"arrow\"></span></a></li></ul></div>";

Also, you forgot to close the DIV.

Instead, you could do something like this (outside <?php and ?>):

<div id="content">
  <ul class="pageitem">
    <li class="store">
      <a href="index.html">
        <span class="image" style="background-image: url('<?php echo $zeile['image']; ?>')"></span>
        <span class="name"><?php echo $zeile['title']; ?></span>
        <span class="arrow"></span>
      </a>
    </li>
  </ul>
</div>


Read up on how strings work in PHP:

  • http://php.net/manual/en/language.types.string.php

If you use double quotes you can do this:

echo "<b>{$myarray[$index]}</b>";

Or you can do this:

echo '<a href="'.$src.'">blah</a>';

Note how I used single quotes to avoid having to escape the double quotes. However, with a single quote, I cannot embed the variable within the quote.


Try this

echo "<div id='content'><ul class='pageitem'><li class='store'><a href='index.html'><span class='image' style='background-image: url(" . $zeile['image'] . ")'></span><span class='name'>" . $zeile['title'] . "</span><span class='arrow'></span></a></li></ul></div>";


Do not use

try this:

echo "<div id=\'content\'><ul class=\'pageitem\'><li class=\'store\'><a href=\'index.html\'><span class=\'image\' style=\'background-image: url(".$zeile['image'].")></span><span class=\'name\'>".$zeile['title']."</span><span class=arrow></span></a></li></ul></div>";

Check Single quotes also.

And even I agree with "Parkyprg", use html content outside php.


you may replace each " with "+"\""+". It works in all scripting languages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜