Loading ...
Sorry, an error occurred while loading the content.

php4 and variable substitution

Expand Messages
  • Rajesh Fowkar
    Hi, I am passing the following variables to the php script MasterSelect.php. // Parameters Required to be passed to this script : // $databasename : Name of
    Message 1 of 3 , Sep 27, 2002
    • 0 Attachment
      Hi,

      I am passing the following variables to the php script MasterSelect.php.

      // Parameters Required to be passed to this script :
      // $databasename : Name of the Database,
      // $wherefield : fieldname to be used in Where clause of the Select Query,
      // $orderfield : fieldname to be used in Order By clause of the Select Query,
      // $popupdisplayfield1 : First Field to be displayed in the Select Popup,
      // $popdisplayfield2 : Second Field to be displayed in the Select Popup,
      // $popupvaluefield : Value to be assigned to the Selection.

      include("include/common_func.php");
      disable_cache();


      $dblink = db_connect();
      if ( $prompttxt == "" || empty($prompttxt) )
      {
      $query = "Select * from $databasename order by $orderfield";
      }
      else
      {
      $query = "Select * from $databasename where $wherefield LIKE '%$prompttxt%' order by $orderfield";
      }
      $result = @pg_exec($dblink, $query);
      $numrows = @pg_numrows($result);

      The above stuff works fine. But when I try to put values in the Combo
      box using $popdisplayfield1, $popdisplayfield2 and $popvaluefield it
      returns an error saying some T_STRING expected.

      Here is the code :

      echo "<option value=''>--Select--</option>";
      for($row=0; $row < $numrows; $row++)
      {
      $ans = @pg_fetch_object($result, $row, PGSQL_ASSOC);
      echo "<option value='$ans->$popupvaluefield'>$ans->$popupdisplayfield1 - $ans->$popupdisplayfield2</option>";
      };

      However in the echo line if I replace $popdisplayfield1 with store_code,
      $popdisplayfield2 with storename and $popvaluefield with store_code it
      works. Can not this thing be generalised by passing the above parameters
      ? What am I doing wrong ?

      Can anybody enlighten me ?

      Thanks in advance.

      Peace

      --
      Rajesh
      :
      ####[ Linux One Stanza Tip (LOST) ]###########################

      Sub : vi mode display (through ~/.exrc) LOST #204

      vi clones operate in command, insert, append or display modes
      which for newcomers, is difficult to discern. To have the mode
      displayed constantly at the right bottom of screen, add to the
      ~/.exrc file:

      :set showmode

      ####<bish@...>####################################
      :
    • MagNet WebPublishing Pvt. Ltd.
      Hi Rajesh, The simplest thing would be to use fetch_array instead of fetch_object. Note also the concatenation used, instead of putting everything in a single
      Message 2 of 3 , Sep 27, 2002
      • 0 Attachment
        Hi Rajesh,

        The simplest thing would be to use fetch_array instead of fetch_object.
        Note also the concatenation used, instead of putting everything in a
        single string.

        >>>>> code <<<<<
        for($row=0; $row < $numrows; $row++)
        {
        $ans = @pg_fetch_array($result, $row, PGSQL_ASSOC);
        echo "<option
        value='".$ans[$popupvaluefield]."'>".$ans[$popupdisplayfield1]." -
        ".$ans[$popupdisplayfield2]."</option>";
        };
        >>>>> code <<<<<

        Regards,
        Nirav.
        ==================================
        | tangible, customized solutions |
        | for your e-business |
        ==================================
        | http://www.magnet-i.com/ |
        ==================================



        -----Original Message-----
        From: Rajesh Fowkar [mailto:mail@...]
        Sent: Friday, September 27, 2002 3:05 PM
        To: Indian PHP User's Group
        Subject: [in-phpug] php4 and variable substitution


        Hi,

        I am passing the following variables to the php script MasterSelect.php.

        // Parameters Required to be passed to this script :
        // $databasename : Name of the Database,
        // $wherefield : fieldname to be used in Where clause of the Select
        Query,
        // $orderfield : fieldname to be used in Order By clause of the Select
        Query,
        // $popupdisplayfield1 : First Field to be displayed in the Select
        Popup,
        // $popdisplayfield2 : Second Field to be displayed in the Select
        Popup,
        // $popupvaluefield : Value to be assigned to the Selection.

        include("include/common_func.php");
        disable_cache();


        $dblink = db_connect();
        if ( $prompttxt == "" || empty($prompttxt) )
        {
        $query = "Select * from $databasename order by $orderfield"; }
        else {
        $query = "Select * from $databasename where $wherefield LIKE
        '%$prompttxt%' order by $orderfield"; } $result = @pg_exec($dblink,
        $query); $numrows = @pg_numrows($result);

        The above stuff works fine. But when I try to put values in the Combo
        box using $popdisplayfield1, $popdisplayfield2 and $popvaluefield it
        returns an error saying some T_STRING expected.

        Here is the code :

        echo "<option value=''>--Select--</option>";
        for($row=0; $row < $numrows; $row++)
        {
        $ans = @pg_fetch_object($result, $row, PGSQL_ASSOC);
        echo "<option
        value='$ans->$popupvaluefield'>$ans->$popupdisplayfield1 -
        $ans->$popupdisplayfield2</option>";
        };

        However in the echo line if I replace $popdisplayfield1 with store_code,
        $popdisplayfield2 with storename and $popvaluefield with store_code it
        works. Can not this thing be generalised by passing the above parameters
        ? What am I doing wrong ?

        Can anybody enlighten me ?

        Thanks in advance.

        Peace

        --
        Rajesh
        :
      • Rajesh Fowkar
        ... Thanks a lot Nirav. Peace -- Rajesh ... ####[ Linux One Stanza Tip (LOST) ]########################### Sub : Using Aliases (bourne shell/ clones)
        Message 3 of 3 , Sep 27, 2002
        • 0 Attachment
          On Fri, Sep 27, 2002 at 03:37:05PM +0530, MagNet WebPublishing Pvt. Ltd. wrote:

          >Hi Rajesh,
          >
          >The simplest thing would be to use fetch_array instead of fetch_object.
          >Note also the concatenation used, instead of putting everything in a
          >single string.
          >
          >>>>>> code <<<<<
          >for($row=0; $row < $numrows; $row++)
          >{
          > $ans = @pg_fetch_array($result, $row, PGSQL_ASSOC);
          > echo "<option
          >value='".$ans[$popupvaluefield]."'>".$ans[$popupdisplayfield1]." -
          >".$ans[$popupdisplayfield2]."</option>";
          >};
          >>>>>> code <<<<<

          Thanks a lot Nirav.

          Peace

          --
          Rajesh
          :
          ####[ Linux One Stanza Tip (LOST) ]###########################

          Sub : Using Aliases (bourne shell/ clones) LOST #176

          You can use aliases to decrease the amount of typing you need
          to do to get commands you commonly use. These can be inserted
          into your /etc/profile or .profile as well. Under Borne shell
          and clones (ash, bash, ksh, and zsh).

          alias ls="ls --color=auto"
          alias lsd="ls -d */"

          ####<From : freebsd fortune>##################################
          :
        Your message has been successfully submitted and would be delivered to recipients shortly.