Announcement

Collapse
No announcement yet.

How to Use SQL Macros Instead Of mysql_field_name in scriptcase 8.1 version?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Use SQL Macros Instead Of mysql_field_name in scriptcase 8.1 version?

    I want to display field names using SQL Macros / sc macros

    I want to display field names using SQL Macros, but I want to display Table field names eith the help of Sc Macros.

    Actually I find Sc Macros i.e sc_select_field ({Field}) sc_select_order ("Field"), but these are not usefull to me.

    please suggest me of this kind.

  • #2
    I use this code.

    First set this at connection:

    $this->Db->SetFetchMode(ADODB_FETCH_ASSOC);

    then execute your query as usual

    sc_select(ds, " select field1, field2 from table ");
    if ({ds} === false)
    {
    echo "Database error. Message = ". {ds_erro};
    }
    else
    {

    while (! $ds->EOF )
    {

    echo $ds->fields[ "field1"] . "</br>";
    echo $ds->fields[ "field2"] . "</br>";

    $ds->MoveNext();
    }
    $ds->Close();

    }


    list of fields are in $ds->fields associative array.

    Also you ca use FetchFiled to get the type of field.


    Ciao ciao

    Comment


    • #3
      Actually I want to display All Field names(Only Field Name not records form table)

      like

      <?php
      mysql_connect("localhost","root","");
      mysql_select_db("test");
      $sql=mysql_query("select * from album");//id,artist,title are field names in album table
      $fc=mysql_num_fields($sql);
      for($i=0;$i<$fc;$i++)
      {
      $fields=mysql_field_name($sql,$i);
      echo "$fields<br>";
      }
      /*
      out put
      id
      artist
      title
      */
      ?>


      here My output should be like this
      _________________
      | Id | artist | title |
      -----------------------

      not entire table (fields not values)

      Comment


      • #4
        Originally posted by justdoit View Post

        here My output should be like this
        _________________
        | Id | artist | title |
        -----------------------

        not entire table (fields not values)
        as I wrote

        list of fields are in $ds->fields associative array.
        execute the query and check the $ds->fields array, you'll get the list of fields.

        Comment


        • #5
          Here

          I want to Display Only Fields/Field names(not entire table with Values).

          Only Fields
          Like
          _________________
          | Id | artist | title |
          -----------------------

          Can Any one Give me Example with Output .

          Comment


          • #6
            and for the last time.. do only these 3 steps

            1) $this->Db->SetFetchMode(ADODB_FETCH_ASSOC);

            2)

            sc_select(ds, " select field1, field2 from table ");
            if ({ds} === false)
            {
            echo "Database error. Message = ". {ds_erro};
            }

            3) print_r ( $ds->fields );

            Comment


            • #7
              I am getting Out Put like this

              Array ( [Id] => 1 [0] => 1 [artist] => abc [1] => abc [title] => 1 [0] => 1 )


              But I want Result Like Id,artist,title

              Here I am getting
              id=>1
              artist=>abc
              title=>one


              I want to display all field names with select *

              Display Only field headings not all values.....

              Comment


              • #8
                Excuse me, but please stop yelling around and start reading!

                This is probably close to what you want. You can omit the ORDER BY clause if you don't need/want it.

                Code:
                $sql = "SELECT GROUP_CONCAT( COLUMN_NAME ORDER BY column_name SEPARATOR ' | ')
                FROM INFORMATION_SCHEMA.COLUMNS 
                WHERE TABLE_SCHEMA = 'your_database' AND TABLE_NAME = 'your_table'";
                sc_lookup(rs,$sql);
                echo {rs[0][0]};
                :-)

                jsb
                Last edited by jsbinca; 08-24-2015, 09:46 AM.

                Comment


                • #9
                  Good Morning jsbinca can you show me the Output of that.

                  Comment


                  • #10
                    Originally posted by justdoit View Post
                    Good Morning jsbinca can you show me the Output of that.

                    Good Morning
                    I want to display only Field names

                    from a table
                    ________________
                    | Id | artist | title |
                    ---------------------
                    |1 | mp3 | one |
                    |2 | mp4 | two |
                    ----------------------

                    So here with the help of Macros or function I want to display

                    Id , artist , title (that is field names of a table)


                    In previous I used with mysql_field_name();

                    So I want a Sc Macros or function which is equals to mysql_field_name().

                    Thank you
                    Justdoit(MLN).

                    Comment

                    Working...
                    X