Oh why won't it work
| From: | Tom Wollaston | Date: | Mon, 27 Oct 2003 13:00:19 +0000 |
| Subject: | Oh why won't it work | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-167709@lists.php.net to get a copy of this message | ||
I am having problems sorting stuff into an array. It doesn't seem to work
quite how everything I read says it should. It is probably my understanding
of it but either way I don't really know whats going on.
I am trying to put everything out of a table into an array so I can call up
the individual rows by a sequential number and then the information in each
row by a colume heading. so for the name value in row 1 I want to have
$null[1][name].
The purpose of this is to amke a menu system where it automatically sorts
the rows into the relevent order. The parentid associates a row with another
to signify that it comes under that menu heading. I want it to have 3
levels, so I have included 3 loops all looking for data whos parent id is
the same as the previous ones id. If that makes any sence.
But when I run this script, it looses the first row and doesn't really
output anything logical. For now I have commented out 2 of the loops to try
and make it easier to see where I have gone wrong.
To see what output I get http://www.busc.net/bristol/website/admin.php
is
the code that I have included underneath.
Thanks
<html>
<head>
<title>Bristol University Skiclub Admin Section</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="600" height="181" border="0"
align="center">
<tr>
<td>
<?php
include "includes/constants.php";
$link = @mysql_connect($DB_server, $DB_user, $DB_pwd) or die ("Could not
connect");
@mysql_select_db($DB_user) or die ("Could not select database");
$n = 1;
$null=getinfo('0');
for ($i=1; $i<=sizeof($null); $i++);
{
print_r($null);
/* print $nul[$i]['name'];
$j=$null[$i]['id'];
/*$fisrt=getinfo["1"];
for ($k=1; $k<=sizeof($first); $k++);
{
echo $first[$k]['name'];
$l=$first[$k]['id'];
$second=getinfo['$m'];
for ($m=1; $m<=sizeof($second); $m++);
{
echo $second[$m]['name']<br>;
}
}*/
}
?>
</td>
</td>
<td> </td>
</tr>
</table>
</body>
</html>
<?php
function getinfo($pid)
{
$query = "SELECT name,parentid FROM ubsc_menu WHERE parentid='$pid' ORDER
BY parentid";
$result = mysql_query ($query) or die ("Query failed");
$row=mysql_fetch_array($result,MYSQL_ASSOC);
while ($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
foreach ($row as $colname => $value)
{
$array[$n][$colname] = $value;
}
$n++;
}
return $array;
}
?>