promotion image of download ymail app
Promoted

使用MySQL建立table。%s是什麼意思?

最近學PHP和MySQL,看到書中的範例中有%s的出現,請問%s是要幹麻用的?

例如:

ㄧ、

CREATE TABLE %s(

namechar( 25 ) ,

idchar( 25 ) ,

age int( 3 ) ,

descriptionchar( 25 ) ,

emailchar( 25 ) ,

telephonechar( 25 )

)

二、

$query_Recordset1 = sprintf("SELECT * FROM `user` WHERE m_user = %s", $colname_Recordset1);

這些例子都有%s的出現,請問這是要做什麼用的呢?15點,謝謝喔

1 個解答

評分
  • 1 0 年前
    最佳解答

    % - a literal percent character. No argument is required. b - the argument is treated as an integer, and presented as a binary number. c - the argument is treated as an integer, and presented as the character with that ASCII value. d - the argument is treated as an integer, and presented as a (signed) decimal number. e - the argument is treated as scientific notation (e.g. 1.2e+2). u - the argument is treated as an integer, and presented as an unsigned decimal number. f - the argument is treated as a float, and presented as a floating-point number (locale aware). F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3. o - the argument is treated as an integer, and presented as an octal number. s - the argument is treated as and presented as a string. x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters). X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).

    是sprintf的函式在使用

    以你的例子來說

    使設$colname_Recordset1 = 5

    $query_Recordset1的結果為

    SELECT * FROM `user` WHERE m_user = 5";

    再舉例來說明

    echo sprintf("%s %s %s",1,2,3);

    結果會為

    1 2 3

    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。