请帮帮我:)我有这个代码......
while($row = mysql_fetch_array($result))
{
$pid=$row ['pid'];
echo '<div class="single"><div class="wrap">
<div style="text-align:center;">
<a href="http://localhost/wordpress/wp-content/themes/snarfer.php?id=<?php echo $pid ?>">Comments</a>
</br>
<a href="MyOnlineStore/product.php?id=<?php echo $pid?>">View Details</a>
</div>
<a href="'.$path.$row['filename'].'" rel="lightbox[plants]" title="'.$row['alttext'].'"><img src="'.$path.$row['filename'].'" alt="Plants: image 1 0f 4 thumb" /></a>
</div>
</div>';
}
我只是想知道如何回应这个$ pid? tnxp>
答案 0 :(得分:8)
它被认为是一种更好的做法,可以在HTML中回应PHP而不是PHP中的HTML,如下所示:
<?php while($row = mysql_fetch_array($result)): $pid = $row ['pid']; ?>
<div class="single">
<div class="wrap">
<div style="text-align:center;">
<br />
<a href="MyOnlineStore/product.php?id=<?php echo $pid; ?>">View Details</a>
</div>
<a href="<?php echo $path.$row['filename']; ?>" rel="lightbox[plants]" title="<?php echo $row['alttext']; ?>"><img src="<?php echo $path.$row['filename']; ?>" alt="Plants: image 1 0f 4 thumb" /></a>
</div>
</div>
<?php endwhile; ?>
答案 1 :(得分:3)
回答你的问题'如何回应$ pid?'答案是echo $pid;
你也在php中使用php开关标签<?php ?>
开启,这将无效。
我建议你阅读http://php.net/manual/en/function.echo.php并熟悉php的基本原理。
另外,正如@Juanid Bhura写的那样
Its considered a better practice to echo PHP within HTML and not HTML within PHP
答案 2 :(得分:1)
你的语法错了;你有PHP语法-in- php语法。将您的代码更改为以下内容,它应该可以工作:
echo '<div class="single"><div class="wrap">
<div style="text-align:center;">
<a href="http://localhost/wordpress/wp-content/themes/snarfer.php?id=' . $pid . '">Comments</a>
</br>
<a href="MyOnlineStore/product.php?id=' . $pid . '">View Details</a>
</div>
<a href="'.$path.$row['filename'].'" rel="lightbox[plants]" title="'.$row['alttext'].'"><img src="'.$path.$row['filename'].'" alt="Plants: image 1 0f 4 thumb" /></a>
</div>
</div>';
答案 3 :(得分:0)
希望这有帮助,
<a href="MyOnlineStore/product.php?id='.$pid.'">View Details</a>
<?php echo $pid?>
被忽略为普通字符串而未被解析。
答案 4 :(得分:0)
试试这个:
while($row = mysql_fetch_array($result))
{
$pid=$row ['pid'];
echo '<div class="single"><div class="wrap">
<div style="text-align:center;">
<a href="http://localhost/wordpress/wp-content/themes/snarfer.php?id='. $pid .'">Comments</a>
</br>
<a href="MyOnlineStore/product.php?id='.$pid.'">View Details</a>
</div>
<a href="'.$path.$row['filename'].'" rel="lightbox[plants]" title="'.$row['alttext'].'"><img src="'.$path.$row['filename'].'" alt="Plants: image 1 0f 4 thumb" /></a>
</div>
</div>';
}