note 101065 deleted from language.types.array by thiago
| From: | thiago@php.net | Date: | Wed, 24 Nov 2010 12:01:46 +0000 |
| Subject: | note 101065 deleted from language.types.array by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174317@lists.php.net to get a copy of this message | ||
Note Submitter: thesurge0n
----
BEFORE ANYONE EVEN COMMENTS ON MY PROGRAMMING, IT WORKS THEREFORE IT'S FINE.
AND ITS AND EXAMPLE :)
<?php
/*
*Description: Displays top 3 positions...
*/
/*include password file*/
include("./Adverts.php");
/*connect to database*/
$cxn = mysql_connect($host, $user, $passwd)
or die ("Couldn't connect to server.");
/*select database*/
mysql_select_db($dbname);
/*set the query to make*/
$query = "SELECT * FROM
Favourites WHERE Favourites.loginName =
'ANAME'";
/*perform query or error*/
$result = mysql_query($query)
or die ("Couldn't execute query.");
/*add values to $row array*/
while ($row = mysql_fetch_assoc($result))
{
/*removes username from array*/
unset($row['loginName']);
/*sort array in reverse order*/
arsort($row);
/*set $c variable for counting and set to zero*/
$c=0;
/*foreachloop to set Key/Value pair*/
foreach($row as $k => $v)
{
/*add 1 to $c so index is always different*/
$c=$c+1;
/*create a 3 dimensional temp array to store index, Key and Value*/
$tmp = array(
array($k, array($v))
);
/*echo each index, key and value to screen*/
echo "$tmp[$c]['$k']['$v']<br/>";
/*set a condition to break out of loop after showing 3 results*/
if($c == "3")
{
break;
}
}
}
?>