Welcome to WebmasterWorld Guest from 23.21.38.201

Forum Moderators: coopster & jatar k

Whats wrong with this multi dimensional array?

   
4:45 am on Apr 23, 2006 (gmt 0)

10+ Year Member



Here is my code.

$item = array (

array ("name" => "$hurow[name]", "level" => "$hurow[lvl]"),
array ("name" => "$burow[name]", "level" => "$burow[lvl]"),
array ("name" => "$wurow[name]", "level" => "$wurow[lvl]"),
array ("name" => "$surow[name]", "level" => "$surow[lvl]"),
array ("name" => "$gurow[name]", "level" => "$gurow[lvl]"),
array ("name" => "$lurow[name]", "level" => "$lurow[lvl]"),
array ("name" => "$bourow[name]", "level" => "$bourow[lvl]"),
array ("name" => "$e1urow[name]", "level" => "$e1urow[lvl]"),
array ("name" => "$e2urow[name]", "level" => "$e2urow[lvl]"),
array ("name" => "$r1urow[name]", "level" => "$r1urow[lvl]"),
array ("name" => "$r2urow[name]", "level" => "$r2urow[lvl]"),
array ("name" => "$amurow[name]", "level" => "$amurow[lvl]")

);

$x = 0;
while ($x <= 12)
{
if($item[$x][level] > $row['lvl'])
{
$item[$x][name] = "";
echo $item[$x][name];
echo $x;
}
$x++;
}

Its not overly advanced but its not returning any results either.

Can anyone help me out?

5:45 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$item = array (
'name' => array('$hurow[name]', '$burow[name]', '$wurow[name]', '$surow[name]'),
'level' => array('$burow[lvl]', '$wurow[lvl]', '$lurow[lvl]');

List all the rest too.

Habtom

6:07 am on Apr 23, 2006 (gmt 0)

10+ Year Member



ok, this is my new code

$item = array (
'name' => array('$hurow[name]', '$burow[name]', '$wurow[name]', '$surow[name]', '$gurow[name]', '$lurow[name]', '$bourow[name]', '$e1urow[name]', '$e2urow[name]', '$r1urow[name]', '$r2urow[name]', '$amurow[name]'),
'level' => array('$hurow[lvl]', '$burow[lvl]', '$wurow[lvl]', '$surow[lvl]', '$gurow[lvl]', '$lurow[lvl]', '$bourow[lvl]', '$e1urow[lvl]', '$e2urow[lvl]', '$r1urow[lvl]', '$r2urow[lvl]', '$amurow[lvl]')
);

$x = 0;
while ($x <= 12)
{
if($item[$x][level] > $row['lvl'])
{
$item[$x][name] = "";
echo $item[$x][name];
echo $x;
}
$x++;
}

It doesnt seem to be working either, now this is my first time using arrays so i do not even know how to test them lol, someone tell me Im on the right track.

Turk

6:25 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$hurow[name] and the others - do they hold any value?

Hab

6:39 am on Apr 23, 2006 (gmt 0)

10+ Year Member



yes all "names" have a value, only some "levels" have values.

Turk

8:38 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You got to get name and level first as shown below:

while ($x <= 12)
{
if($item[level][$x] > $row['lvl'])
{
$item[name][$x] = "";
echo $item[name][$x];
}
$x++;
}

Habtom

3:25 pm on Apr 23, 2006 (gmt 0)

10+ Year Member



ok I got it just how I want it, for those who are having the same prob Ill post my code

$item = array (

array ("name" => "$hurow[name]", "level" => "$hurow[level]"),
array ("name" => "$burow[name]", "level" => "$burow[level]"),
array ("name" => "$wurow[name]", "level" => "$wurow[level]"),
array ("name" => "$surow[name]", "level" => "$surow[level]"),
array ("name" => "$gurow[name]", "level" => "$gurow[level]"),
array ("name" => "$lurow[name]", "level" => "$lurow[level]"),
array ("name" => "$bourow[name]", "level" => "$bourow[level]"),
array ("name" => "$e1urow[name]", "level" => "$e1urow[level]"),
array ("name" => "$e2urow[name]", "level" => "$e2urow[level]"),
array ("name" => "$r1urow[name]", "level" => "$r1urow[level]"),
array ("name" => "$r2urow[name]", "level" => "$r2urow[level]"),
array ("name" => "$amurow[name]", "level" => "$amurow[level]")
);
$x = 0;
while ($x <= 11)
{
$names[$x] = $item[$x][name];
$levels[$x] = $item[$x][level];
if($levels[$x] > $row['lvl'])
{
echo '<b>'. $names[$x].'</b> Level is to high.<br>';
$names[$x] = "";
}
$x++;
}

then echo variables like so $names[0] $names[4] etc etc

Thanks for all the help.

Turk

12:09 pm on Apr 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



just some tweaking here:

array ("name" => "$hurow[name]", "level" => "$hurow[level]");

can cause some problems by throwing warnings and exceptions. it's better practise to use:

array ("name" => $hurow["name"], "level" => $hurow["level"]);

instead. if it's a need to use array variables between the quotes, embrace them:

array ("name" => "{$hurow[name]}", "level" => "{$hurow[level]}");

but i do not know how to avoid the constant warning here because of using

$hurrow[name]
instead of
$hurrow["name"]
(name is used as constant here which is not defined!)
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month