$sql =  "select * from map where poiType=1";
mysql_connect("localhost","root","root") or die("无法连接MySQL数据库服务器!");
$db = mysql_select_db("map") or die("无法连接数据库!");
$result = mysql_query($sql);
//$num = mysql_num_rows($sql);
$num =0;
while($row = mysql_fetch_array($result))
{

   $points = array(
  $num =>(
array(
'point'=>$row['point'],
'label' => $row['label'],
'title' => $row['title'],
'content' => $row['content']
)));  
   $num++;

}
print_r ($points);
//echo count($points);
echo mysql_num_rows($result);输出结果:01234567Array ( [7] => Array ( [point] => 116.325,39.90854 [label] => ?? [title] => ??? [content] => ??????? ) ) 8怎么取到后一条呢?明明有8条数据?

解决方案 »

  1.   

    $arr[count($arr)-1]//一维的最后一个,照此类推即可
      

  2.   

    $sql = "select * from map where poiType=1";
    mysql_connect("localhost","root","root") or die("无法连接MySQL数据库服务器!");
    $db = mysql_select_db("map") or die("无法连接数据库!");
    $result = mysql_query($sql);
    //$num = mysql_num_rows($sql);
    $num =0;
    while($row = mysql_fetch_array($result))
    {$points[] = array(
    $num =>(
    array(
    'point'=>$row['point'],
    'label' => $row['label'],
    'title' => $row['title'],
    'content' => $row['content']
    )));  
    $num++;}
    print_r ($points);
    //echo count($points);
    echo mysql_num_rows($result);
    你试一下
      

  3.   

    哦,中间应该是这样$points[] = 
    array(
    'point'=>$row['point'],
    'label' => $row['label'],
    'title' => $row['title'],
    'content' => $row['content']
    );  
      

  4.   

    echo ($points[7]['point']);//可以取出值

    echo ($points[1]['point']);//没有输出值,
    事实上数据库里有8条记录
      

  5.   

    $points[] =  
    array(
    'point'=>$row['point'],
    'label' => $row['label'],
    'title' => $row['title'],
    'content' => $row['content']
    ); 
    这是一维的吧
      

  6.   

    while($row = mysql_fetch_array($result))
    {$pointsp[] = array(
    $num =>(
    array(
    'point'=>$row['point'],
    'label' => $row['label'],
    'title' => $row['title'],
    'content' => $row['content']
    )));   
    $num++;}
      

  7.   

    $sql = "select * from map where poiType=1";
    mysql_connect("localhost","root","root") or die("无法连接MySQL数据库服务器!");
    $db = mysql_select_db("map") or die("无法连接数据库!");
    $result = mysql_query($sql);$num =0;
    while($row = mysql_fetch_array($result))
    {
       //$num++可以不要
       $points[$num++] = array(
           'point'=>$row['point'],
           'label' => $row['label'],
           'title' => $row['title'],
           'content' => $row['content']
          );   
    }
      

  8.   

    不好意思,
    $points[] = 
    array(
    'point'=>$row['point'],
    'label' => $row['label'],
    'title' => $row['title'],
    'content' => $row['content']
    ); 
    这是对的,谢谢了