Notice: Array to string conversion - PHP & mySQL

前端 未结 2 1536
梦如初夏
梦如初夏 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 . "<br/>\n";
    }
    }
    

    Hope that helps...

    0 讨论(0)
  • 2021-01-06 09:54

    $row is set in every iteration of the while loop. every time it contains a new table record. So you just need to add each record in the address array.

       while($row = mysql_fetch_assoc($p_address))
       {     
          $address[] = $row;
       }  
    
    0 讨论(0)
提交回复
热议问题