How should i done this in PHP?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sooseong.ng@gmail.com

    How should i done this in PHP?

    Hi,

    I am a newbie and recently just delved into the scripting world of
    PHP. Currently I am doing
    a webform that consists many fields. I have three combobox with state
    selection which
    will retrieve the items from a database table called state. The
    dumbest and direct way would
    be creating a connection and querying the data each time, which means
    three connections
    connected just to querying same piece of information. I am wondering
    if it is possible to
    refactor them into using one connection to query the states, and
    assign the value to each
    combobox. Then i will need not to query thrice. Any idea?

  • Jerry Stuckle

    #2
    Re: How should i done this in PHP?

    sooseong.ng@gma il.com wrote:
    Hi,
    >
    I am a newbie and recently just delved into the scripting world of
    PHP. Currently I am doing
    a webform that consists many fields. I have three combobox with state
    selection which
    will retrieve the items from a database table called state. The
    dumbest and direct way would
    be creating a connection and querying the data each time, which means
    three connections
    connected just to querying same piece of information. I am wondering
    if it is possible to
    refactor them into using one connection to query the states, and
    assign the value to each
    combobox. Then i will need not to query thrice. Any idea?
    >
    Well, first of all, PHP wouldn't create connections for this - PHP is
    strictly server side. But you can use PHP to generate the <option>
    tags for your select boxes when you're building your page.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Michael Fesser

      #3
      Re: How should i done this in PHP?

      ..oO(sooseong.n g@gmail.com)
      I am a newbie and recently just delved into the scripting world of
      >PHP. Currently I am doing
      >a webform that consists many fields. I have three combobox with state
      >selection which
      >will retrieve the items from a database table called state. The
      >dumbest and direct way would
      >be creating a connection and querying the data each time, which means
      >three connections
      >connected just to querying same piece of information.
      It would be just one connection and three queries. Not really a problem,
      but of course you can do it just once and store the result in an array.
      Then use that to create your combo boxes.

      Micha

      Comment

      • Jeff North

        #4
        Re: How should i done this in PHP?

        On Sun, 17 Jun 2007 06:28:25 -0700, in comp.lang.php
        sooseong.ng@gma il.com
        <1182086905.448 400.179110@a26g 2000pre.googleg roups.comwrote:
        >| Hi,
        >|
        >| I am a newbie and recently just delved into the scripting world of
        >| PHP. Currently I am doing
        >| a webform that consists many fields. I have three combobox with state
        >| selection which
        >| will retrieve the items from a database table called state. The
        >| dumbest and direct way would
        >| be creating a connection and querying the data each time, which means
        >| three connections
        >| connected just to querying same piece of information. I am wondering
        >| if it is possible to
        >| refactor them into using one connection to query the states, and
        >| assign the value to each
        >| combobox. Then i will need not to query thrice. Any idea?
        You are probably using
        q1 = SELECT ID,Field1 FROM table
        q2 = SELECT ID,Field2 FROM table
        q3 = SEELCT ID,Field3 FROM table

        You can join these into a single query
        q = SELCT ID, Field1,Field2,F ield3 FROM table

        then build your comboboxs using only the required field(s).
        ---------------------------------------------------------------
        jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
        ---------------------------------------------------------------

        Comment

        Working...