homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Whats wrong with this multi dimensional array?
dkin

10+ Year Member



 
Msg#: 12609 posted 4:45 am on Apr 23, 2006 (gmt 0)

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?

 

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 12609 posted 5:45 am on Apr 23, 2006 (gmt 0)

$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

dkin

10+ Year Member



 
Msg#: 12609 posted 6:07 am on Apr 23, 2006 (gmt 0)

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

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 12609 posted 6:25 am on Apr 23, 2006 (gmt 0)

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

Hab

dkin

10+ Year Member



 
Msg#: 12609 posted 6:39 am on Apr 23, 2006 (gmt 0)

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

Turk

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 12609 posted 8:38 am on Apr 23, 2006 (gmt 0)

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

dkin

10+ Year Member



 
Msg#: 12609 posted 3:25 pm on Apr 23, 2006 (gmt 0)

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

hakre

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 12609 posted 12:09 pm on Apr 24, 2006 (gmt 0)

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!)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved