MySQL选择然后回显结果

时间:2011-02-21 19:13:50

标签: php sql mysql

$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);

这是我在用PHP选择它们之后试图向我展示的行。

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

3 个答案:

答案 0 :(得分:2)

应该是

while ($row = mysql_fetch_row($result_2))

您错过了)

答案 1 :(得分:2)

尝试将mysql_fetch_row更改为mysql_fetch_assoc。前者仅按编号索引结果,而不是按字段名称索引。

答案 2 :(得分:0)

- 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;
+     }
+ }