Basically, I have a class that is used to add a note to the database and it links the note to a particular business.
The for loop goes through all the notes (since you can have multiple for one business) and adds them to an array that is then returned.
The trouble I am having is that the variable $i in the for loop is only recognized as 0 inside of the while, but it shows as the number it is supposed to outside the while.
I need the while to loop through the information in the DB, but I also need the For to get the number it is at. If there is a better way to do this, I would be glad to hear it, but this way worked before so I don't know what I could have done to break it. The code is below:
if($numRows > 0){
$note = array();
for($i = 0; $i < $numRows; $i++){
echo $i; // This shows the correct number
while($n = $db->fetchArray($query)){
echo $i; // This always shows as 0
$note[$i]['noteID'] = $n['noteID'];
$note[$i]["title"] = $n['title'];
$name = $db->getUserName($n['author']);
$note[$i]["author"] = $name['first'] . " " . $name['last'];
$note[$i]["date"] = $n['added'];
$note[$i]["text"] = $n['text'];
echo "<pre>";print_r($note);echo "</pre>";
}
}
return $note;
My brain is slightly fried, so the answer/problem might be obvious.
Thanks ahead of time!