help! repeated key/value conflicts in my array!
Posted: Tue Aug 09, 2005 3:40 pm
Hi eveyone!
I'm not quite sure how to describe my problem as I'm a complete newbie and am still trying to learn all the php terms. But if you have a quick try-out of the menu I'm trying to put together on the following page you'll see exactly what i mean:
http://www.gerrydanaher.com/index.php
I want users to be able to search by topic or by date. However, some of the topics/dates are inevitably going to cross over and it keeps messing things up!
The code i'm using for the Search by Date bit is below (the code for the Search by Topic bit is exactly the same only without the 1's after all the variables etc...
I'd be soooo massively grateful if anyone could tell me what i'm doing wrong - or even just point me towards a tutorial that might help me. I do realise that i'm probably wasting all your time with a really stupid question, and i do want to learn myself what i should be doing, but i've just been searching for hours and i can't find a similar problem anywhere that would give me a hint, and think i could well just be searching under the wrong terms...
Would be grateful for any advice at all!
Yours hopefully,
Lizzyd
I'm not quite sure how to describe my problem as I'm a complete newbie and am still trying to learn all the php terms. But if you have a quick try-out of the menu I'm trying to put together on the following page you'll see exactly what i mean:
http://www.gerrydanaher.com/index.php
I want users to be able to search by topic or by date. However, some of the topics/dates are inevitably going to cross over and it keeps messing things up!
The code i'm using for the Search by Date bit is below (the code for the Search by Topic bit is exactly the same only without the 1's after all the variables etc...
Code: Select all
<?php
// menu title => menu target
$menu1 = array(
'2005'=>array(
'14 October'=>'content.php?yr=04&id=1014',
'20 September'=>'content.php?yr=04&id=0920'),
'2004'=>array(
'19 August'=>'content.php?yr=04&id=0819',
'18 August'=>'content.php?yr=04&id=0818'),
'2003'=>array(
'14 October'=>'content.php?yr=04&id=1014',
'20 September'=>'content.php?yr=04&id=0920'),
'2002'=>array(
'19 August'=>'content.php?yr=04&id=0819',
'18 August'=>'content.php?yr=04&id=0818'),
'2001'=>array(
'8 August'=>'content.php?yr=04&id=0808',
'31 July'=>'content.php?yr=04&id=0731'),
'2000'=>array(
'19 August'=>'content.php?yr=04&id=0819',
'18 August'=>'content.php?yr=04&id=0818'),
'1995'=>array(
'8 August'=>'content.php?yr=04&id=0808',
'31 July'=>'content.php?yr=04&id=0731')
);
// alternative method to using cookies
function array_search_recursive1($needle1, $haystack1) {
$pos1 = null;
$keys1 = array_keys($haystack1);
while(!$pos1 && (list($garbage1, $value1)=each($keys1))) {
if(is_scalar($haystack1[$value1])) {
if($haystack1[$value1] === $needle1)
$pos1[] = $value1;
} elseif(is_array($haystack1[$value1])) {
if($pos = array_search_recursive1($needle1, $haystack1[$value1]))
array_unshift($pos1, $value1);
}
}
return $pos;
}
// recursive function to draw menu
function draw_menu1($menu1, $preserve1, &$id1) {
if($id1 == 0)
echo "<div id=\"$id1\">\r\n<ul>\r\n";
else
echo "<div id=\"$id1\" style=\"display:none;\">\r\n<ul>\r\n";
$id1 += 1;
foreach($menu1 as $key1=>$value1) {
if(is_array($value1)) {
if(@in_array($key1, $preserve1))
$toggle1 = $id1;
echo "<li class=\"top\"><a href=\"#\" onclick=\"toggle($id1);\">$key1</a></li>\r\n";
draw_menu1($value1, $preserve1, $id1);
}
else {
echo "<li>";
if(@in_array($key1, $preserve1))
echo "<a href=\"$value1\">$key1</a>";
else
echo "<a href=\"$value1\">$key1</a>";
echo "</li>\r\n";
}
}
echo "</ul>\r\n</div>\r\n";
if(isset($toggle1))
echo "<script language=\"javascript\">toggle($toggle1);</script>\r\n";
}
$id1 = 0;
$base1 = basename($_SERVER['PHP_SELF']);
$self1 = isset($_SERVER['QUERY_STRING']) ? $base1.'?'.$_SERVER['QUERY_STRING'] : $base1;
$preserve1 = array_search_recursive1($self1, $menu1);
draw_menu1($menu1, $preserve1, $id1);
?>Would be grateful for any advice at all!
Yours hopefully,
Lizzyd