-1

我有以下函数将整行拉入数组但我想做的是在数组中使用 en,de,es,fr,it 的行标题,就像我在底部的示例一样

function translateWord($word,$lang){
    $result = mysql_query("SELECT * FROM tbl_translate WHERE en = '$word'");
    if (!$result) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    $row = mysql_fetch_row($result);
    print_r($row);
}
translateWord('hi','fr');

回复

1 [1] => hi [2] => 你好 [3] => 你好 [4] => bonjour [5] => ciao )

需要是

1 [en] => hi [de] => hallo [es] => hola [fr] => bonjour [it] => ciao )

4

1 回答 1

4

采用mysql_fetch_assoc()

$row = mysql_fetch_assoc($result);
print_r($row);

[en] => hi [de] => hallo [es] => hola [fr] => bonjour [it] => ciao )
于 2013-01-23T14:14:38.600 回答