array can not sort!
Posted: Tue Jun 07, 2005 2:21 am
Hello
I use php4.3.2
I wrote this script but array can not sort!
Why?! please help me.
*******************************
********************************
result in browser:
DVD-RPMK ----> 42
DVD-MATR ----> 40
DVD-UNSG ----> 30
DVD-UNSG2 ----> 30
DVD-FDBL ----> 24600
DVD-DHWV ----> 32800
DVD-LTWP ----> 29000
DVD-SPEED ----> 32000
DVD-SPEED2 ----> 3500
And when i delete this:
arsort($m);
But result in browser is like above!
Why arsort do not sort my array?
JCART | Please use
I use php4.3.2
I wrote this script but array can not sort!
Why?! please help me.
*******************************
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?
$host = "localhost";
$user = "myname";
$password = "mypass";
$dbname = "mydb";
$tablecat = "products_to_categories";
$tableproducts = "products";
$link = mysql_connect($host,$user,$password);
$query1 = "SELECT * from $tablecat where (categories_id = $cat)";
$result1 = mysql_db_query ($dbname,$query1,$link);
while ($row = mysql_fetch_array($result1)) {
$query2 = "SELECT * from $tableproducts where (products_id = $row[0])";
$result2 = mysql_db_query ($dbname,$query2,$link);
while ($row2 = mysql_fetch_array($result2)) {
$a = $row2[2];
$b = $row2[4];
$b = round($b);
$m = array($a=>$b);
}
arsort($m);
reset($m);
for ($n = 0; $n < count($m); $n++) {
$line = each ($m);
print ("$line[key] ----> $line[value] <br> \n ");
}
}
?>
</body>
</html>result in browser:
DVD-RPMK ----> 42
DVD-MATR ----> 40
DVD-UNSG ----> 30
DVD-UNSG2 ----> 30
DVD-FDBL ----> 24600
DVD-DHWV ----> 32800
DVD-LTWP ----> 29000
DVD-SPEED ----> 32000
DVD-SPEED2 ----> 3500
And when i delete this:
arsort($m);
But result in browser is like above!
Why arsort do not sort my array?
JCART | Please use
Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]