Without going too deep into your code, I think I see (parts of) your
problem.

In a nearly similar case, I used this code to deal with the problem.


// This  example is putting the data from a table into a 2-dimentional
array:

// When using  mysql_data_seek(....) you have all the selections from the
query in an array, an you can point to which row you want at any time.
// Remember: the rowpointer "row_num"  starts at 0 and runs to "max_rows" -
1.

 $query = "SELECT *.....

 $max_rows = mysql_num_rows($result);
 $row = mysql_fetch_array($result);
  $row_num = 0;
  $ix = 0;
  while ($row_num <= $max_rows-1) {
      mysql_data_seek($result,$row_num);
   $row = mysql_fetch_array($result);
   $ix++;
   $array[$ix] [1]= $row[1];
   $array[$ix] [2]= $row[2];
   $array[$ix] [3]= $row[3];
  $row_num++;
  }

Hopes this helps a bit.

Regards
Reidar Solberg

"Tom Wollaston" <[EMAIL PROTECTED]> skrev i melding
news:[EMAIL PROTECTED]
> 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>
>     &nbsp;</td>
>     <td>&nbsp;</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;
>
> }
> ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to