Home Backend Development PHP Tutorial 隔行换色的老有关问题

隔行换色的老有关问题

Jun 13, 2016 am 10:46 AM
bgcolor echo gt quot

隔行换色的老问题?
想实现在网页上显示隔行换色的功能,我用的是下面的第二种方法,理论上是可以的啊,结果全是一种颜色,后来查了查,还有第一种方法,挺好用的。只是想知道第二种方法那里出了问题,很困惑,以前都行的,查了好多资料,没有详解,求高手指点……

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->      //方法一      while($result=mysql_fetch_array($query)){    $bgcolor=($bgcolor=="blue") ? "white" : "blue";    echo "<tr bgcolor="{$bgcolor}">";    echo "<td><a href="detail.php?gid=%7B%24result%5B'gid'%5D%7D">{$result['gname']}</a></td>";    echo "<td>{$result['endtime']}</td>";    echo "<td>{$result['current_price']}</td>";    echo "<td>{$result['reply_num']}</td>";    echo "</tr>";      }      //方法二       $flag=1;      while($result=mysql_fetch_array($query)){    if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white"; //这种方式理论上可以阿    echo "<tr bgcolor="{$bgcolor}">";    echo "<td><a href="detail.php?gid=%7B%24result%5B'gid'%5D%7D">{$result['gname']}</a></td>";    echo "<td>{$result['endtime']}</td>";    echo "<td>{$result['current_price']}</td>";    echo "<td>{$result['reply_num']}</td>";    echo "</tr>";    $flag++;      }
Copy after login


------解决方案--------------------
为毛不用jquery在前端做??代码取余效率是个问题
------解决方案--------------------
if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white";

$bgcolor !!!

自己写错了,怪谁呢?
------解决方案--------------------
楼主先输出$flag % 2
echo $flag % 2;echo '
';
看看是不是x0x0x0x0x0的格式。如果是的。在看是不是css样式问题
style="background:颜色"
------解决方案--------------------
探讨
if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white";

$bgcolor !!!

自己写错了,怪谁呢?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Fix: Snipping tool not working in Windows 11

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

Go language development essentials: 5 popular framework recommendations

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

How to Fix Can't Connect to App Store Error on iPhone

Implementing distributed task scheduling using Golang's web framework Echo framework Implementing distributed task scheduling using Golang's web framework Echo framework Jun 24, 2023 am 11:49 AM

Implementing distributed task scheduling using Golang's web framework Echo framework

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher?

See all articles