Home > Backend Development > PHP Tutorial > php里面怎么循环嵌入html元素

php里面怎么循环嵌入html元素

WBOY
Release: 2016-06-23 14:00:02
Original
1601 people have browsed it

 


  •                     

    中奖信息


                        

                                                $sql = "select * from t_activity where MemberID='$memberID'";
                           $res = $db->GetData($sql);
                          
                           while ($res)
                           {
                          
    • 1

    •                     
                           }
                           $obj = mysqli_fetch_object($res);
                           ?>
                             
                          

                      
                    


  • 如上面,从数据库取出数据来后,怎么从数据库结果集中循环输出想要的数据在html的li里面?


    回复讨论(解决方案)

    <li data-role="collapsible">	<h1>中奖信息</h1>	<ul>		<?php 		$sql = "select * from t_activity where MemberID='$memberID'";		$res = $db->GetData($sql);				while ($obj = mysqli_fetch_object($res))		{			?>			<li><?php echo $obj->字段 ;?></li>			<?php		}				?>			</ul>	</li>
    Copy after login
    Copy after login
    Copy after login
    Copy after login

    <li data-role="collapsible">	<h1>中奖信息</h1>	<ul>		<?php 		$sql = "select * from t_activity where MemberID='$memberID'";		$res = $db->GetData($sql);				while ($obj = mysqli_fetch_object($res))		{			?>			<li><?php echo $obj->字段 ;?></li>			<?php		}				?>			</ul>	</li>
    Copy after login
    Copy after login
    Copy after login
    Copy after login

    大神就是大神!膜拜下!

    还有个问题请教:
    $sql = "select count(*) from t_activity where MemberID='$memberID'";
    $res = $db->ExecSql($sql);
    $num = mysqli_num_rows($res);
    问下mysql,怎么统计查询count(*) 的行数,用上面的方法一直不成功!


    <li data-role="collapsible">	<h1>中奖信息</h1>	<ul>		<?php 		$sql = "select * from t_activity where MemberID='$memberID'";		$res = $db->GetData($sql);				while ($obj = mysqli_fetch_object($res))		{			?>			<li><?php echo $obj->字段 ;?></li>			<?php		}				?>			</ul>	</li>
    Copy after login
    Copy after login
    Copy after login
    Copy after login

    大神就是大神!膜拜下!

    还有个问题请教:
    $sql = "select count(*) from t_activity where MemberID='$memberID'";
    $res = $db->ExecSql($sql);
    $num = mysqli_num_rows($res);
    问下mysql,怎么统计查询count(*) 的行数,用上面的方法一直不成功!
    $num打印出来是什么?



    <li data-role="collapsible">	<h1>中奖信息</h1>	<ul>		<?php 		$sql = "select * from t_activity where MemberID='$memberID'";		$res = $db->GetData($sql);				while ($obj = mysqli_fetch_object($res))		{			?>			<li><?php echo $obj->字段 ;?></li>			<?php		}				?>			</ul>	</li>
    Copy after login
    Copy after login
    Copy after login
    Copy after login

    大神就是大神!膜拜下!

    还有个问题请教:
    $sql = "select count(*) from t_activity where MemberID='$memberID'";
    $res = $db->ExecSql($sql);
    $num = mysqli_num_rows($res);
    问下mysql,怎么统计查询count(*) 的行数,用上面的方法一直不成功!
    $num打印出来是什么?

    打印出来1,但数据库有3条

    打印出来1,但数据库有3条
    把count(*)换成* 就可以了

    或者这样也可以

    $row = mysqli_fetch_row($res);$num = $row[0];
    Copy after login


    打印出来1,但数据库有3条
    把count(*)换成* 就可以了

    大神!

    $num = mysqli_fetch_row($res);
    echo $num[0];

    或者
    list($num) = mysqli_fetch_row($res);

    或者
    $num = crrrent(mysqli_fetch_row($res));

    source:php.cn
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template