html标签如何使用php中的变量

查看:138
本文介绍了html标签如何使用php中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

html标签中使用php变量,提示:Undefined index: uid in /var/www//list.php
,list.php的具体代码如下:

<?php

    require 'redis.php';
    for ($i=0; $i <= ($redis->get("userid")) ; $i++)
    {
        $data[] = $redis->hgetall("user:".$i);
    }
    /* var_dump($data) 的结果如下:
    array (size=3)
  0 => 
    array (size=0)
      empty
  1 => 
    array (size=4)
      'uid' => string '1' (length=1)
      'username' => string 'jjj' (length=3)
      'password' => string '123' (length=3)
      'age' => string '20' (length=2)
  2 => 
    array (size=4)
      'uid' => string '2' (length=1)
      'username' => string 'lamp' (length=4)
      'password' => string '123' (length=3)
      'age' => string '20' (length=2)
      */
?>

<table border="1">
    <caption>user list</caption>
    <tr>
        <th>uid</th>
        <th>username</th>
        <th>age</th>
    </tr>
    <?php foreach ($data as $v) {?>

    <tr>
        <td><?php echo $v['uid'] ?></td>
        <td><?php echo $v['username'] ?></td>
        <td><?php echo $v['age'] ?></td>
    </tr>
    <?php } ?>
</table>

解决方案

echo 前 isset 下不就可以了吗

这篇关于html标签如何使用php中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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