我得到的输出
Name Age
ABC 12
PQR 40
XYZ 10
使用PHP从MySql数据库检索数据的代码。
//Get records from database
$result = mysql_query("SELECT * FROM people;");
//Add all records to an array
$rows = array();
$count = 0;
while($row = mysql_fetch_array($result))
{
// Here i want to bind one more colomn for count as Row number to array
count = count + 1;
$rows[] = $row;
}
期望的输出..
RowNo Name Age
1 ABC 12
2 PQR 40
3 XYZ 10
我想用mysql data as one colomn
发送计数。有人可以指导我吗?
答案 0 :(得分:2)
while($row = mysql_fetch_array($result))
{
$count = $count + 1;
$row['RowNo']= $count; //Just add this
$rows[] = $row;
}
答案 1 :(得分:0)
试试这个
$counter = 0;
for($i = 0; $i < count($result); $i++)
{
$counter++;
$result[$i]['rowcount'] = $counter;
}