> while( $res=$UDV -> getDbAns()) { // fetch mains
Just checking:
On success, $UDV->getDbAns() returns array of string;
On fail, it returns false.
> if(strlen($res[0]) > 2) { // if result is OK
> $menarr[$h]=$res[0]; // put them in array
Here is your problem - you set $menarr[$h] to
a string, then later try to set stringval[$s][$h] to
a string. Unsurprisingly, PHP has no idea how to
treat a string as a 2d array.
> // get submenues
> $selchi="select chi from link where pa = '$res[0]'";
Try echoing this string to make sure it is what you think;
might have to be
... where pa = '{$res[0]}' ";
> $UDB -> talk2DB($selchi);
> while($chia=$UDB -> getDbAns()) {
> if(strlen($chia[0]) >3) { // if result is OK
> //echo "<b>".$chia[0]."</b><br>";
> // Youll get a <0x20> separated string
> $subp=explode(" ",$chia[0]); // explode it, to get single values
> if(is_array($subp)) { // if there are more than one in it
... the result of explode() is _always_ an array; this
test and the alternate code are unnecessary.
> $maxs=count($subp); // check out how many
> for($n=0; $n < $maxs ; $n++) { // each child in main/sub/n
why not use foreach() ? not much difference, maybe,
just a bit easier to follow...
> // put the value in main/sub/n
> error here -> $menarr[$h][$s][$n]=$subp[$n];
as above, $menarr[$h] is a string.
> }
> }
>del else // if there�s only one value
>del {
>del $menarr[$h][$s][0]=$chia[0];
>del }
> }// end if sub
> $s++; // submenues plus one
You never set $s to 0; your submenus are going to be
numbered funny, ie
$menarr[0][0]
$menarr[0][1]
$menarr[0][2]
$menarr[1][3]
$menarr[1][4]
etc
> }// end while subs
> }// end if main
>
> $h++; // mainmenues plus one
> }// end while mainmenues
Here is my reorganized code:
$h = 0;
while ( $res = $UDV->getDbAns() ) {
if ( strlen($res[0]) <= 2 )
continue; // skip invalid results ('--' ?)
$menarr[$h]['menu'] = $res[0]; // store menu name
$child_query = "SELECT chi FROM link WHERE pa='{$res[0]}' ";
$UDB->talk2DB($child_query);
$s = 0;
while ( $child = $UDB->getDbAns() ) {
if ( strlen($child[0]) <= 3 ) {
continue;
$subp = explode(" ", $child[0]);
foreach($subp as $key => $val)
$menarr[$h][$s][$key] = $val;
$s++;
}
$h++;
}
Hope this helps.
P.S. ... it seems to me the query-in-query could be
replaced by a single sorted query; the result would
probably be a little faster, but (shrug) save that for later.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php