0

I am trying to convert an array to its value.

I am getting this:

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 ) 

Here is my code:

<?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));
                        
                    }
            
        }   
        

?>
1
  • Well, if it's doing what it's supposed to do I would assume you're doing it right... Commented Mar 3, 2010 at 5:33

2 Answers 2

1

You're iterating over $name_id, so as such you normally wouldn't handle $name_id in its entirety within the loop. It is fairly unclear what you are trying to do, but as a first step you should be dealing with array_values() outside of the loop.

Sign up to request clarification or add additional context in comments.

Comments

1

You SQL query fetches the note_id field from your database -- and only that one.

Using mysql_fetch_assoc, each time the while loop iterates, $data_row will contain the data of one line of your notes table, which could be accessed using :

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

So, your code might look like this :

$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 />';
}


And if you want some additionnal data from the notes table, you'll have to select a couple more fields in your SQL query (for instance) :

$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 />';
}


i.e. no need for two loops : the while loop is enough to go through each line of data returned from the database -- and you can read each different column using $data_row['name of the column'].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.