PHP Variable in Select Statement

前端 未结 7 584
滥情空心
滥情空心 2021-01-13 17:50

I\'ve written this PHP-Script which is working, and now I want to change the row name into a variable to (not sure if row is correct), I mean the \"name\" from the selec

7条回答
  •  耶瑟儿~
    2021-01-13 18:23

    Is it this you're looking for? Even your question in German isn't that clear to me :

    $field = 'name';
    $query = mysql_query("SELECT $field FROM contacts WHERE contact_id='". mysql_real_escape_string( $id ) ."' and user_id='1';");
    $retval = mysql_fetch_object($query)->$field;
    

提交回复
热议问题