www.webdeveloper.com
Results 1 to 3 of 3

Thread: IF Else nightmare!

  1. #1
    Join Date
    Jun 2004
    Location
    los angeles
    Posts
    324

    IF Else nightmare!

    Ive got a download section that someone else worked on previously and I am thinkig of ways how I can recreate the code behind it making it easier. I am seeing down the road and it loooks like its gonna be a mess if I continue coding it like the way it is. This is how it works:

    - There is a form with some check boxes (right now 5). Based on the check box a user selects, they get to donwload that specific PDF file.
    - Once selected, then on the code there is a bunch of if else statements that check for the combination of PDF file selections a user might have. Example:

    if pdf = 1 then
    <a href="/pdf1.pdf" target="_blank">
    else if
    if pdf = 2 then
    <a href="/pdf3.pdf" target="_blank">

    but where it gets tricky is when a user selects for example pdf files 1,3,5 then I have to start bulding more if else statements that will meet all different selections a user might select.

    if pdf ="1, 3, 5" then
    <a href="/pdf1.pdf" target="_blank">
    <a href="/pdf3.pdf" target="_blank">
    <a href="/pdf5.pdf" target="_blank">

    currently there is about 220 lines of just if else statements that try go accomodate for a users different selection criteria they might want. They plan on adding more pdf files for downloads and I am seeing a nightmare!

    I have some ideas like putting the PDF names on arrays and having a pointers extract the specified file. But ughg, I think there might a shorter way to do this. I would like some input from you guys to see if some ideas can be sparked. Thanks Community!

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    name the checkboxes as pdf[] that forces the checkbox values into a sub array of $_POST, example
    PHP Code:
    <?php
    if($_POST)
    {
        if(!empty(
    $_POST['pdf']))
        {
            while(list(, 
    $v) = each($_POST['pdf']))
            {
                
    $v intval($v);

                if(
    $v 0)
                {
                    echo 
    "<a href=\"/pdf{$v}.pdf\" target=\"_blank\">PDF $v</a><br>\n";
                }
            }
        }
    }
    ?>

  3. #3
    Join Date
    Dec 2006
    Posts
    35
    I'd suggest:
    PHP Code:
    <?php 
    if($_REQUEST

        if(!empty(
    $_REQUEST['pdf'])) 
        { 
            while(list(, 
    $v) = each($_REQUEST['pdf'])) 
            {

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles