Have probleme with switch{

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
talehc
Forum Newbie
Posts: 2
Joined: Mon Sep 26, 2005 11:26 pm

Have probleme with switch{

Post by talehc »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hello
I'am generating my menu from a function using variables from arrays of items,


the index page has the following code

Code: Select all

<body topmargin="0"> 
<? 

//DECLARING ROOT VARIABLES 
$web_root="http://localhost/wembadesign2"; 
$server_root="d:/WEBSITES/2005/wembadesign2/"; 

//LOADING VARIABLES AND FUNCTIONS 
include("$server_root/lib/variables_en.php"); 
include("$server_root/lib/functions.php"); 

//LOADING ROOT FILES 
include("$server_root/headers.php"); 
include("$server_root/top.php"); 
include("$server_root/body.php"); 
include("$server_root/footer.php"); 

?>


these are my arrays of items for the menus

Code: Select all

//MENU ARRAYS 
//1 
$menu_mainmenu=array(1,"Main Menu","What's So Special ?","Fast & Free Updated","Packages","What Does It Cost ?","Is It Worth It ?","What do I Need ?","Getting Started","Order Now"); 
//2 
$menu_packages=array(2,"Our Packages","Starter","Premium","Silver","Gold","Platinum"); 
//3 
$menu_news=array(3,"News","News","Events","Reviews"); 
//4 
$menu_top=array(4,"Home","Home","About the Project","Mailling List","Policies","Contact Us","Back To Wemba.com"); 

?>



this is the function generating the menus

Code: Select all

<? 

// FUNCTION TO GENERATE MENUS FROM MENU ARRAYS 
function show_menu($menu){ 

global $web_root, $server_root; 

$menu_total=count($menu); 

echo "<table width=100% border=0 cellpadding=0 cellspacing=0> 
<tr><td background='$web_root/images/gradient_menu.gif' valign='middle'> 

<table width=100% border=0 cellpadding=2 cellspacing=1> 
<tr><td background='$web_root/images/gradient_menu.gif' align='center'> 
<font class=menuTitles><center><b> $menu[1] </b></font> 
</td></tr>"; 

$bg=array("#ffffff"); 

//and(time()); 
shuffle($bg); 

for ($i=2;$i<$menu_total;$i++){ 


$total_bg=(count($bg)-1); 

//gID=rand(0,$total_bg); 

$bgID=$menu[0]; 

$bgcolor=$bg[$bgID]; 

echo "<tr> 
<td bgcolor=$bgcolor> 
<img src='$web_root/images/green_arrow.gif' border=0 alt='green arrow'> <font class=mainContent><a href='$web_root/?link=$menu[0]$i'>$menu[$i]</a></font></td></tr>\n"; 

} 
echo "</table> 
</td></tr></table>&nbsp;"; 

} 


?>




this is the main page in which i include my pages file.tpl


Code: Select all

<td> 

<? 

//Link ID correction 
if (isset($link)) 

{ 
$link=""; 
} 

else 
{ 
$link=$link; 
} 



switch ($link) 
{ 

//1 Main Contain 

case 12 :include("$server_root/templates/contain/template_sospecial.tpl"); break; 
case 13 : include("$server_root/templates/contain/template_updated.tpl"); break; 
case 14 : include("$server_root/templates/contain/template_intropackages.tpl"); break; 
case 15 : include("$server_root/templates/contain/template_cost.tpl"); break; 
case 16 : include("$server_root/templates/contain/template_worth.tpl"); break; 
case 17 : include("$server_root/templates/contain/template_need.tpl"); break; 
case 18 : include("$server_root/templates/contain/template_start.tpl"); break; 
case 19: include("$server_root/templates/contain/template_order.tpl"); break; 

//2 Packages 
case 22 : include("$server_root/templates/packages/template_Pstarter.tpl"); break; 
case 23 : include("$server_root/templates/packages/template_Ppremium.tpl"); break; 
case 24 : include("$server_root/templates/packages/template_Psilver.tpl"); break; 
case 25 : include("$server_root/templates/packages/template_Pgold.tpl"); break; 
case 26 : include("$server_root/templates/packages/template_Pplatinum.tpl"); break; 

//3 News 
case 32 : include("$server_root/templates/news/template_Nnews.tpl"); break; 
case 33 : include("$server_root/templates/news/template_Nevents.tpl"); break; 
case 34 : include("$server_root/templates/news/template_Nreviews.tpl"); break; 


//4 Top Menu 
case 42 : include("$server_root/templates/template_home.tpl"); break; 
case 43 : include("$server_root/templates/contain/template_about.tpl"); break; 
case 44 : include("$server_root/templates/contain/template_mailling.tpl"); break; 
case 45 : include("$server_root/templates/contain/template_policies.tpl"); break; 
case 45 : include("$server_root/templates/contain/template_contact.tpl"); break; 

default : include("$server_root/templates/contain/template_policies.tpl"); 

} 

?> 


</td>

my menu doesn't work

but the default value of the switch are displayed normally, please tell me what is wrong ?
regards


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post by ruchit »

try using this

Code: Select all

for ($i=1;$i<$menu_total;$i++)
instead of

Code: Select all

for ($i=2;$i<$menu_total;$i++)
PS: pls put your code in appropraite code tags... it makes them more readable.
talehc
Forum Newbie
Posts: 2
Joined: Mon Sep 26, 2005 11:26 pm

counting from 1

Post by talehc »

i have try but still the same error, and i'am countng from '2' because the first item in any arrayis the menu mane
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

Code: Select all

if (isset($link))

{
$link="";
}

else
{
$link=$link;
}
I don't spose you mean...

Code: Select all

if (!isset($link)
by any chance?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you aware that arrays start counting from zero by default? So this

Code: Select all

for ($i=1;$i<$menu_total;$i++){
would in fact reference all but the first element of the array.
Post Reply