Since i've changed to PDO, i really can't seem to get the right function to use that would do exactly what mysqli_fetch_array() was doing, this happens probably because i don't realy understand the real diffrence between mysqli_fetch_array and PDO's fecth().
From some sources, while($row = mysqli_fetch_array($query) "fetches a single row from the resultset each time it is called.", whereas $row = $query->fetch() is returning the whole resultset in one single call.
I've asked two similar questions and one with a bounty but i can't seem to get a proper way around what i want to do.
- mysql_fetch_array = fetch(PDO::FETCH_BOTH) - The rows are arrays with both numeric and named indexes.
- mysql_fetch_assoc = fetch(PDO::FETCH_ASSOC) - The rows are arrays with named indexes.
- mysql_fetch_row = fetch(PDO::FETCH_NUM) - The rows are arrays with numeric indexes.
- mysql_fetch_object = fetch(PDO::FETCH_OBJ) or fetch(PDO::FETCH_CLASS) depending on whether you specify the optional className argument to mysql_fetch_object. The rows are objects, either of the specified class or stdClass.
- The while loop is equivalent to:
$data = $query->fetchAll(PDO::FETCH_BOTH),
Using the first on this list just seems to behave differently from what mysqli_fetch_arrray does.
What i've tried returns so many errors in the while loop and crushes the browser at times, thanks to Chrome, i won't post that.
HERE's what i want to do.
$counter = 0;
while($row = mysqli_fetch_array($query)){
$counter++;
echo $counter;
echo $row['Name'];
}
If we have three rows: RESULT;
1
TRIQUESHA
2
STACEY
3
DAQUEN
NOW PDO
$count = 0;
while($row = $query->fetch(PDO::FETCH_BOTH)){
$counter++;
echo $counter;
echo $row['Name'];
}
Again if we have three rows: PDO RESULT;
3
TRIQUESHA
3
STACEY
3
DAQUEN
It's not counting, its returning the total number of rows instead, if i had 50 rows, it would repeat 50 on each row.
What am I doing wrong?