Ok, I have this array: $myarray en I want to print just the first element of it, later on the second, but not as a total array.
I'm trying this, but it gives me an error (Warning: Invalid argument supplied for foreach() in /Users/Kim/Sites/snooze/phpinclude/feedbackcontentday1.php on line 8)
foreach ($myarray as $value) {
                echo $value."";
                }
Here's the code from the array:
public function getFeedback($p_iUserid) {
    include("Connection.php"); //open db
    try
    {
        $sql = "SELECT FeedbackPatient FROM tblFeedback 
          开发者_C百科      WHERE fk_UserId = ".$p_iUserid."";
        $result = mysqli_query( $link, $sql );
        while( $row=mysqli_fetch_assoc($result) )
        {
            $myarray[] = $row['FeedbackPatient'];
        }
            print_r($myarray);
        mysqli_free_result( $result );
    }
    catch(Exception $e)
    {
        // no connection database
        $feedback = $e->getMessage();
    }
    mysqli_close($link);
}
First elememt starts with 0 therefore you can use...
// First element
echo $myarray[0];
// Second element
echo $myarray[1];
I thought it was something like:
foreach( $myarray as $key => $value ) {
  echo $value."";
  break;
}
Try this:
public function getFeedback($p_iUserid) {
    include("Connection.php"); //open db
    try
    {
        $sql = "SELECT FeedbackPatient FROM tblFeedback WHERE fk_UserId = ".$p_iUserid."";
        $result = mysqli_query( $link, $sql );
        $myarray = array( );
        while( $row=mysqli_fetch_assoc($result) )
        {
            $myarray[] = $row['FeedbackPatient'];
        }
        print_r($myarray);
        mysqli_free_result( $result );
    }
    catch(Exception $e)
    {
        // no connection database
        $feedback = $e->getMessage();
    }
    mysqli_close($link);
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论