dongzhong8834 2016-01-23 09:19
浏览 73

如何在使用switch case重定向时获取所选的类别ID。

In my project we have to chose categories and it shows the subcategories of corresponding categories. After choosing subcategories it redirecting to that particular page. for redirection, switch case is used. now the problem is now I want to get the subcategories which I chosen in first page is shown in a redirected page. I don't want to put manually for each and every page. because i got more then 35 pages and subcategories. some of the categories and subcategories having same page to redirect, so i want to get the subcategories dynamically.

Here is my coding for index page:

 <select name="category" class="form-control" id="category" >
                <option value="">select category</option>
                <?php
                    $qCategory       = mysql_query("select * from `category` order by id asc");
                    while($rCategory = mysql_fetch_assoc($qCategory)){
                ?>
                        <option value="<?php print $rCategory['id'];?>"><?php print $rCategory['name'];?></option>
                <?php
                    }
                ?>
                </select></div><div class="form-group"><label for="ListingSubcategoryId"> </label>
                <select name="sub_category" id="sub_cat" class="form-control" style="display:none;">
                </select>

i get my sub categories through javascript. i use this in a form, and a form action is going to next page and that page i got the id of the particular subcategory, put id into switch case and redirect to some page.

<?php

   if(isset($_POST['Submit']));
  {
     $cat= $_POST["category"];
     $subcat= $_POST["sub_category"]
     switch ($cat) {
    case '2':
      header('Location: step3.php?cat='.$cat.'sub='.$subcat);
      break;
     case '3':
      header('Location: step3.php?cat='.$cat.'sub='.$subcat);
      break;
     case '4':
      header('Location: step4.php?cat='.$cat.'sub='.$subcat);
      break;
    }
}
?>

Now I want that page is redirected by which id has to been display on particular page. here in the coding case case 2 and 3 id has same page. but id is different. so that I need dynamically show the subcategory in the page. i also display the "id" in URL. but i dont know how to pick that id into my page. please, any one give some idea.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法