루프

2011-09-25 6 views
0

내가 MySQL 데이터베이스에서 데이터를 가져 오는 동안 오전 PHP에서 배열의 인덱스를 찾는 방법 ... 나는 예컨대루프

while($row=mysql_fetch_array($result) 
{ 
i want index of $row in each row... (current Index). 
} 

나를 제발 도와주세요 ... 각 행의 인덱스를 확인합니다. 감사

+3

'$ 전 = 0;'루프 전에'$ 내가 ++; 루프 본문의 끝에' – zerkms

답변

10

필요하지 않습니다, 가정 : 나는 당신의 질문에서 이해 무엇

<?php 
.. 
$result = mysql_query("SELECT * FROM whatever"); 
$index = 0; 

while($row = mysql_fetch_array($result)) { 
    echo $index.' '.$row['whatever']; 
    $index++; 
} 
.. 
?> 

..

0

내가 당신을 이해하면 제대로이

<?PHP 
$i=0; 
while($someThingIsTrue) { 
    echo $i; 
    $i++; 
} 
?> 
0

$ 행과 같은 어떤 배열의 멤버가 아닙니다합니다. 그래서 전혀 색인이 없습니다. 당신은 출력에 따라 항목의 수를 계산하려면,

<?php 
... 
$result = mysql_query("SELECT * FROM whatever"); 

while($row = mysql_fetch_array($result)) { 
    echo $row['index']; 
    # Where index is the field name containing the item ID from your database 
} 
... 
?> 

또는 :
, 나는 당신이 데이터베이스에서 인덱스를 원하는 경우 그것을 하나