Php MySQL选择并回显结果

Php MySQL选择并回显结果,php,sql,mysql,Php,Sql,Mysql,这就是我在用PHP选择并编辑行之后试图显示的内容 这似乎不起作用-有人能帮我吗?:) 应该是 $sql_2 = 'SELECT id, firstname, lastname, birthday, location, occupation, telephone, email, picture FROM pinkmoon_pending ORDER BY `id` DESC LIMIT 1'; $result_2 = mysql_query($sql_2); while ($row = mysq

这就是我在用PHP选择并编辑行之后试图显示的内容

这似乎不起作用-有人能帮我吗?:)

应该是

$sql_2 = 'SELECT id, firstname, lastname, birthday, location, occupation, telephone, email, picture FROM pinkmoon_pending ORDER BY `id` DESC LIMIT 1';
$result_2 = mysql_query($sql_2);

while ($row = mysql_fetch_row($result_2)
{
   $firstname = row['firstname'];
   $lastname  = row['lastname'];
   $birthday  = row['birthday'];
   $location  = row['location'];
   $occupation= row['occupation'];
   $telephone = row['telephone'];
   $email     = row['email'];
   $picture   = row['picture'];
}
mysql_free_result($result_2);
你错过了一个
应该是

$sql_2 = 'SELECT id, firstname, lastname, birthday, location, occupation, telephone, email, picture FROM pinkmoon_pending ORDER BY `id` DESC LIMIT 1';
$result_2 = mysql_query($sql_2);

while ($row = mysql_fetch_row($result_2)
{
   $firstname = row['firstname'];
   $lastname  = row['lastname'];
   $birthday  = row['birthday'];
   $location  = row['location'];
   $occupation= row['occupation'];
   $telephone = row['telephone'];
   $email     = row['email'];
   $picture   = row['picture'];
}
mysql_free_result($result_2);

您错过了一个
尝试将
mysql\u fetch\u行
更改为
mysql\u fetch\u assoc
。前者只按数字而不是字段名对结果进行索引。

尝试将
mysql\u fetch\u row
更改为
mysql\u fetch\u assoc
。前者只按数字而不是按字段名对结果进行索引。

当您将结果限制为最多1行时,不需要执行循环,
如果
就足够了。在使用关联数组时使用
mysql\u fetch\u assoc
。当您将结果限制为最多1行时,不需要执行循环,如果
就足够了。当使用关联数组时,请使用
mysql\u fetch\u assoc
。虽然您是正确的,但它仍然无法工作。看看Kaivosukeltaja的答案。虽然你是正确的,但它仍然不起作用。见Kaivosukeltaja的答案。
- while ($row = mysql_fetch_row($result_2)
- {
-    $firstname = row['firstname'];
-    $lastname  = row['lastname'];
-    $birthday  = row['birthday'];
-    $location  = row['location'];
-    $occupation= row['occupation'];
-    $telephone = row['telephone'];
-    $email     = row['email'];
-    $picture   = row['picture'];
- }

+ while ($row = mysql_fetch_row($result_2)) {
+     foreach ($row as $item) {
+         echo $item;
+     }
+ }