$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条数据?
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条数据?
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);
你试一下
array(
'point'=>$row['point'],
'label' => $row['label'],
'title' => $row['title'],
'content' => $row['content']
);
而
echo ($points[1]['point']);//没有输出值,
事实上数据库里有8条记录
array(
'point'=>$row['point'],
'label' => $row['label'],
'title' => $row['title'],
'content' => $row['content']
);
这是一维的吧
{$pointsp[] = array(
$num =>(
array(
'point'=>$row['point'],
'label' => $row['label'],
'title' => $row['title'],
'content' => $row['content']
)));
$num++;}
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']
);
}
$points[] =
array(
'point'=>$row['point'],
'label' => $row['label'],
'title' => $row['title'],
'content' => $row['content']
);
这是对的,谢谢了