html - Sorting top three using mysql/php -
i want 3 entities highest value database, sort them , place them in each div's scoreboard top three. able separate fields (id, name, description etc.) , retrieve using example:
<?php echo $sql['id']; ?>
i know code retrieve info , sort it:
$sql = ("select * table order tablefield desc limit 3");
but don't know how place 3 entities each div's , separate entity's fields name, description etc.
if using mysql (pdo), highly recommend, it's done follows:
$sql = "select * table order tablefield desc limit 3"; $stmt = $conn->prepare($sql); $stmt->execute(); /*here multidimentional array information wanted*/ $rows = $stmt->fetchall(pdo::fetch_assoc); //this 1 method of extracting information //if want place them in specific divs //question suggests, use array //inside divs instead echoing them out in //this foreach loop foreach ($rows $row) { foreach ($row $key => $value) { echo $key.": ".$value."<br>"; } echo "<br>"; } /*alternatively use: print_r($rows); if want have quick @ composition of array*/
Comments
Post a Comment