[PHP] easier than switch

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: [PHP] easier than switch

    skate wrote:
    > okay, so i know there's an easy way to do this, and i've seen it done, sure of it. so please forgive the stupidity of my question, i don't even know where to begin to look in the archives either...
    >
    > i have several forms on one page, they all submit a different variable, i then want to set one variable depending on that... okay, now i'm confusing myself, lets try explain it with some code...
    >
    > <?
    >
    > if(isset($_POST))
    > {
    > $type = $_POST['news'] || $_POST['dreams'] || $_POST['storys'] || $_POST['words'] || $_POST['chat'];
    > }
    >
    > ?>
    >
    > obviously this doesn't work. but i wanna set $type depending on which $_POST variable was sent. only one of these will ever be sent. rather than doing a big ass switch statement, is there no way i can get this into one line?
    >
    > i hope this isn't too confusing...
    >
    If you're really sure only one will be sent:

    $type = $_POST['news'] . $_POST['dreams'] . $_POST['storys'] .
    $_POST['words'] . $_POST['chat'];

    will achieve what you're looking for.

    --
    ---John Holmes...

    Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]

    PHP|Architect: A magazine for PHP Professionals – [url]www.phparch.com[/url]




    John W. Holmes Guest

  2. Similar Questions and Discussions

    1. Macrons, there must be an easier way...
      Hi, I've had a look @ the forum search & manual... but am still confused as to a simple (or any) approach to creating macrons. This is something I...
    2. easier than switch
      On Mon, Aug 04, 2003 at 11:19:42PM +0100, skate wrote: You have a single page, containing multiple forms, all of which share the same action? ...
    3. [PHP] Is there an easier way?
      Hello, This is a reply to an e-mail that you wrote on Fri, 1 Aug 2003 at 02:04, lines prefixed by '>' were originally written by you. statement...
    4. Is there an easier way?
      Hi, This is what i am doing, querying a database via a select statement (getting max 5 records), then dumping everything into an associative array....
    5. Tell me how it was easier???
      Your steps: 1. Draw 5 filled squares. 2. Group the squares. 3. Double click the contents to change the color of the fills. 4. Duplicate the group...
  3. #2

    Default Re: [PHP] easier than switch

    --- skate <root@fatcuban.com> wrote:
    > i have several forms on one page, they all submit a different variable
    The best solution would be to change this behavior, or at least add a
    consistent form variable that you plan to receive.
    > <?
    > if(isset($_POST))
    > {
    > $type = $_POST['news'] || $_POST['dreams'] || $_POST['storys'] ||
    > $_POST['words'] || $_POST['chat'];
    > }
    > ?>
    >
    > obviously this doesn't work. but i wanna set $type depending on which
    > $_POST variable was sent.
    What you need to do is name your variable 'type', so that $_POST['type'] is
    either 'news', 'dreams', 'stories', 'words', or 'chat'.

    Hope that helps.

    Chris

    =====
    Become a better Web developer with the HTTP Developer's Handbook
    [url]http://httphandbook.org/[/url]
    Chris Shiflett Guest

  4. #3

    Default Re: [PHP] easier than switch

    As, in this case, only one of the variables is non-null, then you could use
    the string concatenation operator and this would return what you want.

    i.e. type = $_POST['news'] . $_POST['dreams'] . $_POST['storys']...

    I think I've used the same variable name in different forms on the same page,
    as only one form submission occurs at any one time there can't be a conflict
    and PHP doesn't care where the POST'ed variable came from.. So, you could
    rename news, dreams, etc. to be type and extract the result directly without
    having to fiddle around.

    HTH

    Nick

    On Monday 04 Aug 2003 11:19 pm, skate wrote:
    > okay, so i know there's an easy way to do this, and i've seen it done, sure
    > of it. so please forgive the stupidity of my question, i don't even know
    > where to begin to look in the archives either...
    >
    > i have several forms on one page, they all submit a different variable,i
    > then want to set one variable depending on that... okay, now i'm confusing
    > myself, lets try explain it with some code...
    >
    > <?
    >
    > if(isset($_POST))
    > {
    > $type = $_POST['news'] || $_POST['dreams'] || $_POST['storys'] ||
    > $_POST['words'] || $_POST['chat']; }
    >
    > ?>
    >
    > obviously this doesn't work. but i wanna set $type depending on which
    > $_POST variable was sent. only one of these will ever be sent. rather than
    > doing a big ass switch statement, is there no way i can get this into one
    > line?
    >
    > i hope this isn't too confusing...
    Nicholas Robinson Guest

  5. #4

    Default PHP/JavaScript/HTML

    Hello folks

    I wrote a JavaScript to set the values of a Select html object by client
    side. The values are copied from another Select that I create getting the
    values from the database. After the user set the values he/she wants to add
    it in another form, for example, then press submit button, the values of the
    "user" Select object doesn't appears on the next page. What can I do to get
    the user selected values in the another page?

    Someone could help me?

    Thanks!
    ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. :.:.:.
    Maurício Alegre Valente
    AGP5 Tecnologia da Informação Ltda.
    (48) 439-3004
    Visite nosso site: [url]www.agp5.com.br[/url]
    ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. :.:.:.
    ----- Original Message -----
    From: "Nicholas Robinson" <npr@bottlehall.freeserve.co.uk>
    To: "skate" <root@fatcuban.com>; <php-general@lists.php.net>
    Sent: Tuesday, August 05, 2003 4:26 AM
    Subject: Re: [PHP] easier than switch

    > As, in this case, only one of the variables is non-null, then you could
    use
    > the string concatenation operator and this would return what you want.
    >
    > i.e. type = $_POST['news'] . $_POST['dreams'] . $_POST['storys']...
    >
    > I think I've used the same variable name in different forms on the same
    page,
    > as only one form submission occurs at any one time there can't be a
    conflict
    > and PHP doesn't care where the POST'ed variable came from.. So, you could
    > rename news, dreams, etc. to be type and extract the result directly
    without
    > having to fiddle around.
    >
    > HTH
    >
    > Nick
    >
    > On Monday 04 Aug 2003 11:19 pm, skate wrote:
    > > okay, so i know there's an easy way to do this, and i've seen it done,
    sure
    > > of it. so please forgive the stupidity of my question, i don't even know
    > > where to begin to look in the archives either...
    > >
    > > i have several forms on one page, they all submit a different variable,
    i
    > > then want to set one variable depending on that... okay, now i'm
    confusing
    > > myself, lets try explain it with some code...
    > >
    > > <?
    > >
    > > if(isset($_POST))
    > > {
    > > $type = $_POST['news'] || $_POST['dreams'] || $_POST['storys'] ||
    > > $_POST['words'] || $_POST['chat']; }
    > >
    > > ?>
    > >
    > > obviously this doesn't work. but i wanna set $type depending on which
    > > $_POST variable was sent. only one of these will ever be sent. rather
    than
    > > doing a big ass switch statement, is there no way i can get this into
    one
    > > line?
    > >
    > > i hope this isn't too confusing...
    >
    >
    > --
    > PHP General Mailing List (http://www.php.net/)
    > To unsubscribe, visit: http://www.php.net/unsub.php
    Mauricio Guest

  6. #5

    Default Re: [PHP] PHP/JavaScript/HTML

    From: "Mauricio" <mauricio@agp5.com.br>
    > I wrote a JavaScript to set the values of a Select html object by client
    > side. The values are copied from another Select that I create getting the
    > values from the database. After the user set the values he/she wants to
    add
    > it in another form, for example, then press submit button, the values of
    the
    > "user" Select object doesn't appears on the next page. What can I do to
    get
    > the user selected values in the another page?
    Well, if I understand that correctly, you need to use Javascript to "select"
    all of the options that the user selected to add to the second select box.
    If they aren't selected, then they won't be passed to the next page.

    ---John Holmes...

    Cpt John W. Holmes Guest

  7. #6

    Default Re: [PHP] PHP/JavaScript/HTML

    Ok! Now I can see the values in the another page. But each value are passed
    with the same name. How can I get all values using PHP script?

    On the Address Bar I can see: index.php?slcAdd=1&slcAdd=2&slcAdd=3
    But when I get the value using $HTTP_GET_VARS['slcAdd']; it returns just the
    last value. What can I do to get them all?

    Thanks!

    ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. :.:.:.
    Maurício Alegre Valente
    AGP5 Tecnologia da Informação Ltda.
    (48) 439-3004
    Visite nosso site: [url]www.agp5.com.br[/url]
    ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. :.:.:.
    ----- Original Message -----
    From: "CPT John W. Holmes" <holmes072000@charter.net>
    To: "Mauricio" <mauricio@agp5.com.br>; <php-general@lists.php.net>
    Sent: Tuesday, August 05, 2003 10:05 AM
    Subject: Re: [PHP] PHP/JavaScript/HTML

    > From: "Mauricio" <mauricio@agp5.com.br>
    > > I wrote a JavaScript to set the values of a Select html object by client
    > > side. The values are copied from another Select that I create getting
    the
    > > values from the database. After the user set the values he/she wants to
    > add
    > > it in another form, for example, then press submit button, the values of
    > the
    > > "user" Select object doesn't appears on the next page. What can I do to
    > get
    > > the user selected values in the another page?
    >
    > Well, if I understand that correctly, you need to use Javascript to
    "select"
    > all of the options that the user selected to add to the second select box.
    > If they aren't selected, then they won't be passed to the next page.
    >
    > ---John Holmes...
    >
    >
    > --
    > PHP General Mailing List (http://www.php.net/)
    > To unsubscribe, visit: http://www.php.net/unsub.php
    Mauricio Guest

  8. #7

    Default Re: [PHP] PHP/JavaScript/HTML

    From: "Mauricio" <mauricio@agp5.com.br>
    > On the Address Bar I can see: index.php?slcAdd=1&slcAdd=2&slcAdd=3
    > But when I get the value using $HTTP_GET_VARS['slcAdd']; it returns just
    the
    > last value. What can I do to get them all?
    Name your select box as "slcAdd[]" and you'll have all of the values in an
    array.

    ---John Holmes...

    Cpt John W. Holmes Guest

  9. #8

    Default RES: [PHP] PHP/JavaScript/HTML

    Perfect! That's all I had to do.

    Thanks!

    Maurício

    -----Mensagem original-----
    De: CPT John W. Holmes [mailto:holmes072000@charter.net]
    Enviada em: terça-feira, 5 de agosto de 2003 16:30
    Para: Mauricio; [email]php-general@lists.php.net[/email]
    Assunto: Re: [PHP] PHP/JavaScript/HTML


    From: "Mauricio" <mauricio@agp5.com.br>
    > On the Address Bar I can see: index.php?slcAdd=1&slcAdd=2&slcAdd=3
    > But when I get the value using $HTTP_GET_VARS['slcAdd']; it returns just
    the
    > last value. What can I do to get them all?
    Name your select box as "slcAdd[]" and you'll have all of the values in an
    array.

    ---John Holmes...


    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php
    ---
    Incoming mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.510 / Virus Database: 307 - Release Date: 14/8/2003

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.510 / Virus Database: 307 - Release Date: 14/8/2003

    Mauricio Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139