我对PHP和MySQL非常陌生,正试图从MySQL表中获取数据并打印它。我打电话给数据库,它很好。我可以阅读信息。出。但数据中有重复。 到目前为止,我有:MySQL和PHP重复打印
<?php
/// Make a MySQL Connection
mysql_connect("localhost", "loop", "XXX") or die(mysql_error());
mysql_select_db("loop") or die(mysql_error());
// Retrieve all the data from the "profile" table
$result = mysql_query("SELECT * FROM profile")
or die(mysql_error());
//print out info.
while ($row = mysql_fetch_array($result)) {
echo("<pre>");
var_dump($row);
echo("</pre>");
}
?>
这将产生:
array(1) {
[0]=>
array(14) {
[0]=>
string(1) "1"
["id"]=>
string(1) "1"
[1]=>
string(13) "[email protected]"
["email"]=>
string(13) "[email protected]"
[2]=>
string(8) "passcode"
["pass"]=>
string(8) "passcode"
[3]=>
string(4) "John"
["nameFirst"]=>
string(4) "John"
[4]=>
string(5) "Smith"
["nameLast"]=>
string(5) "Smith"
[5]=>
string(8) "face.jpg"
["pic"]=>
string(8) "face.jpg"
[6]=>
string(16) "Some dummy text."
["bio"]=>
string(16) "Some dummy text."
}
}
为什么它有重复的元素呢?我检查了数据库,它是确定的。有人可以解释我缺少的东西吗?
考虑使用新的方法,如mysqli的..答案是从PHP文档以下:要获取的数组的类型。它是一个常量,可以取下列值:MYSQL_ASSOC,MYSQL_NUM和MYSQL_BOTH。 MYSQL_BOTH是默认值。 – user993553