How to use PHP variable in Javascript?

前端 未结 5 1335
遇见更好的自我
遇见更好的自我 2021-01-22 23:18

I know you can\'t directly use PHP variables inside javascript code, but is there a way around it? I need to use these parameter\'s in javascript:

username: \'&l         


        
5条回答
  •  轮回少年
    2021-01-22 23:19

    If you have selected only one column (and expect 1 row), you can use:

    $user_id = mysql_result($user_id, 0);
    

    which would fetch the 1st column of the 1st row of the result set $user_id.

    But for clarity's sake you should rename the variable $user_id, because it's not an ID but a resource (so call it $userQuery or something =)).

提交回复
热议问题