你如何在html表格行中使用echo? [英] How do you use echo inside html table row?

查看:125
本文介绍了你如何在html表格行中使用echo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML tr 标签内使用了 echo ,因此我收到错误消息。

b
$ b

这是我的代码



index.php

 <?php 
$ i = 0;
while($ row = mysql_fetch_array($ ros))
{
if($ i%2 == 0)
$ classname =evenRow;
else
$ classname =oddRow;
echo'< tr class =id>';
echo'< tr class ='echo $ classname'>';
?>

我遇到以下错误:


解析错误:语法错误,意外的T_ECHO,在
中期待','或';'E:\xampp\htdocs\pagination\index.php on line 64


我在哪里出错了,我该如何实现我想要的输出?

提前致谢 解决方案

问题不是你在一个表行内,而是你在一个PHP字符串内,答案是:你没有。



您可以:


  • 插值您的变量

  • 连接变量

  • 不要对外部输出使用echo和字符串
>

例如:

 <?php 
$ i = 0 ;
while($ row = mysql_fetch_array($ ros)){
if($ i%2 == 0){
$ classname =evenRow;
} else {
$ classname =oddRow;
?>
< tr class =id>
< tr class =<?php echo $ classname;?>>
<?php
}
#...

注意:你似乎试图嵌套表格行,这是不允许的。



你可以省略奇数/偶数类名称,只需使用:nth-​​child(奇数):nth-​​child(偶数)


I am using echo inside the HTML tr tag where I am getting an error.

Here is my code

index.php

<?php
$i=0;
    while($row=mysql_fetch_array($ros))
    {
    if($i%2==0)
$classname="evenRow";
else
$classname="oddRow";
echo '<tr class="id" >';
echo '<tr class="'echo $classname'">';
?>

I am getting following error:

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in E:\xampp\htdocs\pagination\index.php on line 64

Where am I going wrong and how can I achieve my desired output?

Thanks in advance

解决方案

The problem is not that you are inside a table row, but that you are inside a PHP string, and the answer is: You don't.

You either:

  • Interpolate your variable
  • Concatenate your variable
  • Don't use echo and a string for the outside output

Such:

<?php
$i=0;
while($row=mysql_fetch_array($ros)) {
    if($i%2==0) {
        $classname="evenRow";
    } else {
        $classname="oddRow";
?>
<tr class="id">
    <tr class="<?php echo $classname; ?>">
<?php
    }
# ...

NB: You appear to be trying to nest table rows, which isn't allowed.

You can probably dispense with the odd/even class names and just use :nth-child(odd) and :nth-child(even) in your stylesheet.

这篇关于你如何在html表格行中使用echo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆