开发者

Print one line of an array

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜