php - Resetting array pointer in PDO results -


i'm having trouble moving mysql select methods pdo methods. want iterate through fetched array twice, both times starting row zero. in mysql use:

mysql_data_seek($result,0); 

using pdo methods, i'm not sure how accomplish same thing. code below how trying this. first while loop works fine second while loop returns nothing. can please tell me i'm going wrong?

$pdo = new pdo('mysql:host=' . $host . ';dbname='.$database, $username, $password); $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);  $stmt = $pdo->prepare('select * mytable active = 1 order name asc'); $stmt->setfetchmode(pdo::fetch_assoc); $stmt->execute();  while($row = $stmt->fetch()) {     //do starting row[0] } while($row = $stmt->fetch()) {     //do else starting row[0] } 

thanks help.

save results array , loop array twice.

$pdo = new pdo('mysql:host=' . $host . ';dbname='.$database, $username, $password); $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);  $stmt = $pdo->prepare('select * mytable active = 1 order name asc'); $stmt->setfetchmode(pdo::fetch_assoc); $stmt->execute();  $rows = $stmt->fetchall();  foreach ($rows $r) {     // first run }  foreach ($rows $r) {     // seconds run } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -