Answers for "echo php fetch assoc"

PHP
1

how to reverse fetch assoc in php

while($row = mysql_fetch_assoc($result)){
    $items[] = $row;
}

$items = array_reverse($items ,true);

foreach($items as $item){
   echo $item['time']." - ".$item['username']." - ".$item['message'];
}

//another option can be

$query = mysql_query("SELECT * FROM (
                      SELECT time, username, message
                      FROM messages ORDER BY time 
                      DESC LIMIT 10) result 
                      ORDER BY time ASC   
                    ");
Posted by: Guest on July-01-2020
0

php print fetch

<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Exercise PDOStatement::fetch styles */

print("PDO::FETCH_OBJ: ");
print("Return next row as an anonymous object with column names as propertiesn");
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->name;
print("n");
?>
Posted by: Guest on August-24-2021

Browse Popular Code Answers by Language