把cityid='涧西区' or cityid='西工区' or cityid='老城区' 这三个值的结果分别循环列出 $i从1到6也循环列出<?php 
$sql=mysql_query("SELECT * from zlove_user where cityid='涧西区' or cityid='西工区' or cityid='老城区'and flag=0 order by userid asc limit 0,6",$conn);
while ($row=mysql_fetch_array($sql))
  {
$userid=$row[userid];
$username=$row[username];
$userimg=$row[userimg];
$sex=$row[sex];
$age=$row[age];
$height=$row[height];
$provinceid=$row[provinceid];
$cityid=$row[cityid];
$monolog=$row[monolog];$i=1;$i<6;$i++;echo "
<DIV id=$i>
<DL><A href=home.php?usid=$userid target=_blank>
  <DT><IMG src=css/123.jpg width=112 height=135></DT>
  <DD>
  <H1><FONT class=floatl>$username</FONT>";
  if($sex == "2"){echo " <B></B></H1>";} else echo " <SPAN></SPAN></H1>"; 
  echo "
  <H2>$age 岁 $height 厘米 $xl </br>所在地:$provinceid $cityid </H2>
  <P>$monolog</P>
  <H3>查看更多交友资料&gt;&gt;</H3>
  </DD></A></DL></DIV>";

?>

解决方案 »

  1.   

    while已经循环了,下面不需要再循环,连接字串用 $a."厘米" 
      

  2.   

    本帖最后由 xuzuning 于 2012-03-12 17:01:29 编辑
      

  3.   

    想最终实现下面的显示<!-- 涧西区 -->
    <DIV id=con_one_1>
     
    <DL><A href=home.php?usid=168004 target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>王薇薇</FONT> <B></B></H1>
      <H2>25 岁 158 厘米  </br>所在地:洛阳 涧西区 </H2>
      <P>可以是一篇日记,一段歌词,一句座右铭,一个有趣的签名档</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>
     
    <!-- 西工区 -->
    <DIV style="DISPLAY: none" id=con_one_2>
     
    <DL><A href=home.php?usid=168003 target=_blank>
      <DT><IMG src=user/i_upload/201203/168003/20120312161358_168003_small.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>李丽娜</FONT> <B></B></H1>
      <H2>24 岁 158 厘米  </br>所在地:洛阳 西工区 </H2>
      <P>可以是一篇日记,一段歌词,一句座右铭,一个有趣的签名档</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL>
    <DL><A href=home.php?usid=168001 target=_blank>
      <DT><IMG src=user/ width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>程晓晓</FONT> <B></B></H1>
      <H2>71 岁 157 厘米  </br>所在地:洛阳 西工区 </H2>
      <P>可以是一篇日记,一段歌词,一句座右铭,一个有趣的签名档</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL>
    <DL><A href=home.php?usid=168000 target=_blank>
      <DT><IMG src=user/ width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>张江伟</FONT> <SPAN></SPAN></H1>
      <H2>73 岁 157 厘米  </br>所在地:洛阳 西工区 </H2>
      <P>可以是一篇日记,一段歌词,一句座右铭,一个有趣的签名档</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>
     
     
    <!-- 老城区 -->
    <DIV style="DISPLAY: none" id=con_one_3>
     
    <DL><A href=home.php?usid=168002 target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>姚继成</FONT> <SPAN></SPAN></H1>
      <H2>26 岁 158 厘米  </br>所在地:洛阳 老城区 </H2>
      <P>可以是一篇日记,一段歌词,一句座右铭,一个有趣的签名档</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>
      

  4.   

    建议你这样写,在同一页面:$sql=mysql_query("SELECT * from zlove_user where cityid='涧西区' or cityid='西工区' or cityid='老城区'and flag=0 order by userid asc limit 0,6",$conn);
    $infor = array();
    while ($row=mysql_fetch_array($sql))
      {
      array_push($infor,$row);
    }
    <?php foreach($infor as $i =>$info){ ?><DIV id=<?=$i?> >
    <DL><A href=home.php?usid=<?=info['userid']?> target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>$info['username']</FONT>";
      <?=(info['sex'] == 2)?" <B></B></H1>":" <SPAN></SPAN></H1>"?>  
      <H2>$info['age']岁 $info['height']厘米 $info['xl']</br>所在地:$info['privinceid']  $info['cityid']</H2>
      <P>$info['monolog']</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>";<?php } ?>
      

  5.   

    上面没加全短标记,这样:<?php foreach($infor as $i =>$info){ ?><DIV id=<?=$i?> >
    <DL><A href=home.php?usid=<?=info['userid']?> target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>$info['username']</FONT>";
      <?=(info['sex'] == 2)?" <B></B></H1>":" <SPAN></SPAN></H1>"?>  
      <H2><?=$info['age']?>岁 <?=$info['height']?>厘米 <?=$info['xl']?></br>所在地:<?=$info['privinceid']?>  <?=$info['cityid']?></H2>
      <P><?=$info['monolog']?></P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>";<?php } ?>
      

  6.   

    没加全变量符,真失败,再来次:
    <?php foreach($infor as $i =>$info){ ?><DIV id=<?=$i?> >
    <DL><A href=home.php?usid=<?=$info['userid']?> target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl><?=$info['username']?></FONT>";
      <?=($info['sex'] == 2)?" <B></B></H1>":" <SPAN></SPAN></H1>"?>  
      <H2><?=$info['age']?>岁 <?=$info['height']?>厘米 <?=$info['xl']?></br>
    所在地:<?=$info['privinceid']?>  <?=$info['cityid']?></H2>
      <P><?=$info['monolog']?></P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>";<?php } ?>
      

  7.   

    我原本是这样写,想简便一点<!-- 涧西区 -->
    <DIV id=con_one_1>
    <?php 
    $res=mysql_query("SELECT * from zlove_user where cityid='涧西区'and flag=0 order by userid desc limit 0,6");
           while($row=mysql_fetch_array($res))
           {
       $userid=$row[userid]; 
    echo "
    <DL><A href=home.php?usid=$userid target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>$row[username]</FONT>";
      if($row[sex] == "2"){echo " <B></B></H1>";} else echo " <SPAN></SPAN></H1>"; 
      echo "
      <H2>$row[age] 岁 $row[height] 厘米 $xl </br>所在地:$row[provinceid] $row[cityid] </H2>
      <P>$row[monolog]</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL>";
    } ?>
    </DIV><!-- 西工区 -->
    <DIV style="DISPLAY: none" id=con_one_2>
    <?php 
    $res=mysql_query("SELECT * from zlove_user where cityid='西工区'and flag=0 order by userid desc limit 0,6");
           while($row=mysql_fetch_array($res))
           {
       $userid=$row[userid];
    if($row[userimgflag] == "1"){$userimg = "user/$row[userimg]";} 
    elseif($row[sex] == "2"){$userimg = "css/female.gif";} 
    else{$userimg = "css/male.gif";}
    echo "
    <DL><A href=home.php?usid=$userid target=_blank>
      <DT><IMG src=$userimg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>$row[username]</FONT>";
      if($row[sex] == "2"){echo " <B></B></H1>";} else echo " <SPAN></SPAN></H1>"; 
      echo "
      <H2>$row[age] 岁 $row[height] 厘米 $xl </br>所在地:$row[provinceid] $row[cityid] </H2>
      <P>$row[monolog]</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL>";
    } ?>
    </DIV>
    <!-- 老城区 -->
    <DIV style="DISPLAY: none" id=con_one_3>
    <?php 
    $res=mysql_query("SELECT * from zlove_user where cityid='老城区'and flag=0 order by userid desc limit 0,6");
           while($row=mysql_fetch_array($res))
           {
       $userid=$row[userid];
    echo "
    <DL><A href=home.php?usid=$userid target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>$row[username]</FONT>";
      if($row[sex] == "2"){echo " <B></B></H1>";} else echo " <SPAN></SPAN></H1>"; 
      echo "
      <H2>$row[age] 岁 $row[height] 厘米 $xl </br>所在地:$row[provinceid] $row[cityid] </H2>
      <P>$row[monolog]</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL>";
    } ?>
    </DIV>
      

  8.   

    $i=1;
    while ($row=mysql_fetch_array($sql))
      {
    ..............
    ..............
    echo "
    <DIV id=con_one_$i>
    <DL><A href=home.php?usid=$userid target=_blank>
      <DT><IMG src=css/123.jpg width=112 height=135></DT>
      <DD>
      <H1><FONT class=floatl>$username</FONT>";
      if($sex == "2"){echo " <B></B></H1>";} else echo " <SPAN></SPAN></H1>"; 
      echo "
      <H2>$age 岁 $height 厘米 $xl </br>所在地:$provinceid $cityid </H2>
      <P>$monolog</P>
      <H3>查看更多交友资料&gt;&gt;</H3>
      </DD></A></DL></DIV>";
      $i++;
    }
      

  9.   

    查询数据库后,每个<DIV id=con_one_$i>></DIV>放一个值
    比如:
    <DIV id=con_one_1>>cityid='涧西区' 的值</DIV>
    <DIV id=con_one_2>>cityid='西工区' 的值</DIV>
    <DIV id=con_one_3>>cityid='老城区' 的值</DIV>
      

  10.   

    我给的代码执行不出来吗?挑你需要的更改foreach中的内容不就行了吗?
      

  11.   

    你给的代码全部显示在一个DIV标签内了希望实现的是查询数据库后,每个<DIV id=con_one_$i>></DIV>放一个值
    比如:
    <DIV id=con_one_1>>cityid='涧西区' 的值</DIV>
    <DIV id=con_one_2>>cityid='西工区' 的值</DIV>
    <DIV id=con_one_3>>cityid='老城区' 的值</DIV> 
      

  12.   

    各位大仙解决一下啊
    xuzuning
    来解决一下啊