I’ve been having an extremely difficult time trying to find an answer for this. What I want to do is (I think) rather simple, but I can’t find any information on it.
Let’s say I have a table in my database of fruits, and I’d like to do something like…
<?php
require "../body-parts/config.php";
$result = mysql_query('SELECT * FROM fruits ORDER BY name');
$count = 1;
while ($fruit = mysql_fetch_array($result)) {
echo $count++ . " ";
echo $fruit['name'] . "<br>";
}
?>
Now let’s say the output of that is…
1 Apple
2 Cantaloupe
3 Grapes
4 Kiwi
5 Lemon
6 Orange
Now what I would like to do, is grab the number for Kiwi (in this case 4) so that I can use that later… but I don’t know how I can do this.
So in short, how is it I grab the number position in which a value was returned? I do not want to echo it out, I simply want to grab it and stick it in a variable so I can use it again.
Any help is appreciated, thank you.
1 Answer