我想在php里实现用户资料的随机调用,没有调用范围的限制。不知道应该如何写这段随机代码。
我的数据表主要是  username,userid,grade,sex,photo_s      .__TBL_MAIN__.    请各位帅哥哥帮帮小妹

解决方案 »

  1.   

    把资料的id循环放到个数组中 
    再以这个数组的个数为上限生成 int 类型的随即数 比如得到 i
    用 数组【i】即可得到 随即的资料id
      

  2.   

    呵呵说清楚点行不小姐... 
    要不然...怎么帮啊相帮也无能为力啊... 
    向你说的.随机调用的话简单数据库里设置个主键 然后每个ID有自己的数字ID然后用随机数调出来
    比如说 当随机数100的时候调用数字ID100的拥护资料..注意:随机数必须的要有限制哦..
      

  3.   

    这段是网站最新注册的带照片的会员资料调用<?php
    $rt=$db->query("SELECT id,nickname,photo_s FROM ".__TBL_MAIN__." WHERE flag=1 AND photo_s<>'' ORDER BY refresh_time DESC LIMIT 6");
    $total = $db->num_rows($rt);
    if($total>0){
    ?>
    <table width="778" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF" style="border:#EDD4F0 1px solid;">
      <tr>
        <?php
    for($i=1;$i<=$total;$i++) {
    $rows = $db->fetch_array($rt);
    if(!$rows) break;
    ?>
        <td align="center" style="padding-top:10px;padding-bottom:10px;"><table width="50" border="0" cellpadding="2" cellspacing="0" bgcolor="ffffff">
          <tr>
            <td height="50" align="center" style="border:#dddddd 1px solid;" width="480" height="29"><div class="photo100X75"><a href="<?php echo $Global['home_2domain']; ?>/<?php echo $rows[0]; ?>" target="_blank"> <?php echo "<img src=".$Global['up_2domain']."/photo/".$rows[2]." border=0 >";?> </a></div></td>
          </tr>
        </table>
            <table width="50" height="5" border="0" align="center" cellpadding="0" cellspacing="0" >
              <tr>
                <td align="center" valign="top"></td>
              </tr>
            </table>
          <a href="<?php echo $Global['home_2domain']; ?>/<?php echo $rows[0]; ?>" target="_blank" class="666666"><?php echo $rows[1];?></a>
        <?php if ($i % 6 == 0) {?>
      </tr>
      <tr>
        <?php } ?>
        <?php  } ?>
      </tr>
    </table>
    <?php }?>
      

  4.   

    select * from table order by rand()