Php 我做错了吗。将数组转换为数组值

Php 我做错了吗。将数组转换为数组值,php,mysql,Php,Mysql,可能重复: 我正在尝试将数组转换为其值 我明白了: Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42 Array ( [0] => 31 ) Warning: array_values() expects parameter 1 to be array, string given in C:\xa

可能重复:

我正在尝试将数组转换为其值

我明白了:

Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 31 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 32 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 33 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 34 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 35 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 36 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 37 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 38 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 39 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 40 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 41 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 42 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 43 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 44 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 45 )
Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\ReadNotes\mynote.php on line 42

Array ( [0] => 46 ) 
这是我的密码:

<?php

//Starting session

session_start();

//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs

include ('includes/mass.php');

//Set the  session variable

$username = $_SESSION['username'];


//Check to see if logged in

    if (isset($username))

        {

            //Check all databases assoc with the notes for username submissions

            $sql_for_username_submission = "SELECT note_id FROM notes WHERE user = '$username' ORDER BY note_id";

            $get_data = mysql_query($sql_for_username_submission);

            while ($data_row = mysql_fetch_assoc($get_data))

                    {    //Get name_id's in arrays

                         $name_id_array = $data_row; 

                         //Make each one display all information associated with it.

                         foreach($name_id_array as $name_id)

                                  { 
                                        //Convert name_id array to its id number

                                        $number_on_name_id = array_values($name_id);    

                                        echo $number_on_name_id."</br>";                                        

                                  } 

                         print_r (array_values($name_id_array));

                    }

        }   


?>

您正在迭代
$name\u id
,因此通常不会在循环中完整地处理
$name\u id
。目前还不清楚您想做什么,但作为第一步,您应该在循环之外处理
array\u values()

您的SQL查询从数据库中获取
note\u id
字段,并且只获取该字段

使用
mysql\u fetch\u assoc
,每次while循环迭代时,
$data\u row
将包含notes表中一行的数据,可使用以下方法访问:

echo $data_row['note_id'] . '<br />';


i、 e.不需要两个循环:
while
循环足以遍历数据库返回的每一行数据——您可以使用
$data\u row['column'name']
读取每一个不同的列。。。
$sql_for_username_submission = "SELECT note_id FROM notes WHERE user = '$username' ORDER BY note_id";
$get_data = mysql_query($sql_for_username_submission);
while ($data_row = mysql_fetch_assoc($get_data))
{
    // $data_row contains the data for one entry in the DB
    // You could display $data_row here, to see what's in it :
    //print_r($data_row);
    echo $data_row['note_id'] . '<br />';
}
$sql_for_username_submission = "SELECT note_id, your_value FROM notes WHERE user = '$username' ORDER BY note_id";
$get_data = mysql_query($sql_for_username_submission);
while ($data_row = mysql_fetch_assoc($get_data))
{
    // $data_row contains the data for one entry in the DB
    // You could display $data_row here, to see what's in it :
    //print_r($data_row);
    echo $data_row['note_id'] . ' : ' . $data_row['your_value'] . '<br />';
}