douyou8266 2013-08-25 17:23
浏览 18
已采纳

使用$ list ['something']内部<p> [关闭]

How would one use the mysql/php $list['key'] inside a php echo i.e

echo "<p> My Text . $list[''] . </p>";

Thanks In Advance

  • 写回答

2条回答 默认 最新

  • dongyue8640 2013-08-25 17:24
    关注

    It is as simple as that:

    echo "<p> My Text $list[index] </p>";
    

    N. b.: you do not use single quotes (') for the index as you usually would, like in $a=$list['index'];, since the whole thing is already enclosed in double quotes (").

    Correction: Just found out, with indices like 'a b' you still do need the quotes! (Thanks, Jon!)

    Edit: (response to comment)

    That is a competely different thing! Use

    list($var1,$var2) = mysql_fetch_assoc($result);
    

    instead. The list()-construct (is it a function?!?) extracts the values out of the assigned array (in your case the result of your mysql_fetch_assoc()-function). Assuming, that your result set returns values for two columns (otherwise you will have to supply more variables in list()). And then place the variables into your text like

    echo "<p> My Text $var1 and somewhere maybe also $var2 ... </p>";
    

    Still, since you are using mysql_fetch_assoc($result) you could do

    $z=mysql_fetch_assoc($result);
    echo "<p> My Text $z[field1] and somewhere maybe also $z[field2] ... </p>";
    

    with field1 and field2 being the actual column names from your MySQL table.

    It is customary on this site now, to also warn you of the dangers of still using the deprecated mysql_*functions. You should change to the more secure and modern versions of mysqli_*...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题