How to find Index of an array in php while loop [closed]
I am fetching data from MySQL database... I want to check index of each row... e.g
while($row=mysql_fetch_array($res开发者_如何学Pythonult)
{
i want index of $row in each row... (current Index).
}
Please Help me. Thanks
If you want the index from the database:
<?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
}
...
?>
Or, if you want to count the number of items based on the output:
<?php
..
$result = mysql_query("SELECT * FROM whatever");
$index = 0;
while($row = mysql_fetch_array($result)) {
echo $index.' '.$row['whatever'];
$index++;
}
..
?>
That's what I understood from your question..
If I understood you correctly you want something like this
<?PHP
$i=0;
while($someThingIsTrue) {
echo $i;
$i++;
}
?>
$row is not a member of any array. So, it has no index at all.
And, I suppose, you don't need it either
精彩评论