7 Replies - 1571 Views - Last Post: 13 November 2010 - 11:00 AM Rate Topic: ****- 1 Votes

#1 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

switch doesn't work

Posted 13 November 2010 - 06:38 AM

hello am beginner to php and i have problem with following code switch statement does n't work here
<ul style="list-style:none">
<li><a href="gallery.php?branch=<? echo $branch ?>&id=aw" >Awards &amp; Rewards</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=ka"  >Krishna Astami</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=cs" >christams</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=ca" >Compition</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=cs" >Cultural activities</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=gb" >Ghosh Band</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=as" >Activities</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=sa" >Social Activities</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=ns" >National Competion</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=si" >Sankarthi</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=sag" >Scouts And Guides</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=wa" > Welfare Activities</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=sp" >Sports</a></li>
<li><a href="gallery.php?branch=<? echo $branch ?>&id=swc" >State wise Compition</a></li>
<li><a href="gallery.php?branch=<? echo $branch.'&id=mp'; ?>" >Medical Program</a></li>
</ul>

</div>
<?php
//dir_list.php
$default_dir = "gallery/"; 

switch(($_GET['id'])){
case 'aw':$default_dir.="awards and rewards/"; diaplsy($default_dir);break;
case 'ka':$default_dir.="krishnastami/"; diaplsy($default_dir);break;
case 'cs':$default_dir.="christmas/"; diaplsy($default_dir);break;
case 'cn':$default_dir.="awards and rewards/"; diaplsy($default_dir);break;
case "ca":$default_dir.="cultural activities/"; diaplsy($default_dir);break;
case "gb":$default_dir.="ghosh band/"; diaplsy($default_dir);break;
case "as":$default_dir.="housewise activities/"; diaplsy($default_dir);break;
case "sa":$default_dir.="social welfare activities/"; diaplsy($default_dir);break;
case "nc":$default_dir.="nation level science conference/"; diaplsy($default_dir);break;
case "si":$default_dir.="sankranthi/"; diaplsy($default_dir);break;
case "sag":$default_dir.="scots and guides/"; diaplsy($default_dir);break;
case "wa":$default_dir.="social awareness/"; diaplsy($default_dir);break;
case "ss":$default_dir.="sports/"; diaplsy($default_dir);break;
case "swc":$default_dir.="state level compition/";
 diaplsy($default_dir);break;
case "mp" : $default_dir.="medical program/";
 diaplsy($default_dir);break;
default:$default_dir.="awards and rewards/";
 diaplsy($default_dir);
} 



thanks in advance
here after passing parameters to gallery.php?branch=xyz&id=cs
switch is executing default block and any of the case statements are not executing
any one help
thanks in advance

This post has been edited by sidhu_sree: 13 November 2010 - 06:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: switch doesn't work

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,516
  • Joined: 23-August 08

Re: switch doesn't work

Posted 13 November 2010 - 06:43 AM

WTH does "doesn't work" mean??? Please learn how to ask for help properly: by telling us the exact errors you're receiving, or how the program is behaving versus how you expect it to behave. Saying it's not working is completely useless.
Was This Post Helpful? 0
  • +
  • -

#3 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

Re: switch doesn't work

Posted 13 November 2010 - 06:46 AM

here after passing parameters to gallery.php?branch=xyz&id=cs
switch is executing default block and any of the case statements are not executing
any one help
thanks in advance
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,516
  • Joined: 23-August 08

Re: switch doesn't work

Posted 13 November 2010 - 06:56 AM

Works fine for me. Using your parameters I get a $default_dir of gallery/christmas. If I use sag for the id I get gallery/scots and guides.
Was This Post Helpful? 0
  • +
  • -

#5 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

Re: switch doesn't work

Posted 13 November 2010 - 07:04 AM

View PostJackOfAllTrades, on 13 November 2010 - 05:56 AM, said:

Works fine for me. Using your parameters I get a $default_dir of gallery/christmas. If I use sag for the id I get gallery/scots and guides.

i could see parameter passing in url bar but result is null it is displaying the default statement
if it work fine for you then what is problem at my side
does it need any setting or require global declaration
Was This Post Helpful? 0
  • +
  • -

#6 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

Re: switch doesn't work

Posted 13 November 2010 - 07:27 AM

View PostJackOfAllTrades, on 13 November 2010 - 05:43 AM, said:

WTH does "doesn't work" mean??? Please learn how to ask for help properly: by telling us the exact errors you're receiving, or how the program is behaving versus how you expect it to behave. Saying it's not working is completely useless.

for the above code am getting error PHP Notice: Undefined index: id

any one reply
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2988
  • Posts: 10,326
  • Joined: 08-August 08

Re: switch doesn't work

Posted 13 November 2010 - 08:15 AM

If nothing is sent to the page, $_GET['id'] will be undefined. You need to do something like:
if(isset($_GET['id']))
{
   $myvar  = $_GET['id'];
} else {
   $myvar = "";
}
switch($myvar)


You should also think about indenting, as well as code separation. What you're doing now will be really confusing as your code grows.
Was This Post Helpful? 0
  • +
  • -

#8 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

Re: switch doesn't work

Posted 13 November 2010 - 11:00 AM

switch($_GET['id']){ your code }

here nothing is set this can be replace by the
switch($_REQUEST['id']){ your code }

works fine

but here i got another problem am using function called display it will read images in a specified directory it works fine once secondly it is only displayiong the file name but not loading any images so is there any function that load function when called in php
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1