0

I am using php PDO for server connection. just like that

$stmt = $pdo->prepare('call naviSql( ?, ?, ? )');
$stmt->execute( array( $someone, $on_navi, $on_date ) );

while( $row = $stmt->fetch(  )  ) { 

    echo '<a href="http://'.$_SERVER['HTTP_HOST'].'/anbu/home.php?topic='.$row['topic_name'].'" class="list-group-item list-group-item-action justify-content-between"></a>';
}

now after echoing out all the data, how i can remind first row values once again?

Jonas
  • 121,568
  • 97
  • 310
  • 388
kai
  • 13
  • 7

1 Answers1

1

Use fetchAll instead and store all your results in a variable. The first row can then be accessed by its index, i.e.:

// Store all fetched rows in a variable
$results = $stmt->fetchAll();

// Iterate through all your results
foreach($results as $row) {
    echo '<a href="http://'.$_SERVER['HTTP_HOST'].'/anbu/home.php?topic='.$row['topic_name'].'" class="list-group-item list-group-item-action justify-content-between"></a>';
}

// Re-access the first row
$firstRow = $results[0];
print_r($firstRow);
Terry
  • 63,248
  • 15
  • 96
  • 118
  • can u show me how to get the data fom an array which is inside an another array? `$first = $results[$row['topic_name']]` ?? – kai Mar 11 '18 at 14:06
  • @kai That will be `$results[0]['topic_name']`. – Terry Mar 11 '18 at 14:32