Notice: Array to string conversion - PHP & mySQL

前端 未结 2 1535
梦如初夏
梦如初夏 2021-01-06 08:58

I\'ve been reading in every thread in here that is related to this but I always get it wrong.

Please help cause I always get the error

\"Noti

2条回答
  •  别那么骄傲
    2021-01-06 09:44

    Change this line

     $address[] = mysql_result($row, 0 );
    

    To this:

     $address[] = $row;
    

    And then to see the keys and values available in the new $address array, you can do something like this:

     print_r($address);
    

    In order to keep implode() functional, do something like this:

    for ($i = 0; $i < count($address); $i++) {
      $all_address[] = implode(',', $address[$i]);
    }
    

    Final output:

    if ($p_address=mysql_query($email))
    {
    $address = array();
    
    while($row = mysql_fetch_assoc($p_address))
    {     
     $address[] = $row;
    }
    
    for ($i = 0; $i < count($address); $i++) {
      $all_address[] = implode(',', $address[$i]);
    }
    
    // Example for outputting on screen:
    foreach ($all_address as $aa) {
      print $aa . "
    \n"; } }

    Hope that helps...

提交回复
热议问题