Php select using column Field names ?

Hello,
I need some advice using this select
usually I do this
$query = "SELECT * FROM table WHERE title LIKE 'body'";
it works, is fast and no problems.
But now I've a big table [id, ..., ...] and need to select just the row starting with body, so I use body%
question is
How can I select records using the Field property of the MySql table? (Field, Type, Collation, Attributes,...)
I want something like
$query = "SELECT * FROM table WHERE FIELD LIKE 'body_%'";
Thanks
Pluda

ExPluda wrote:
 ok, I know the name of my table, but don´t know the name of the fields, or I know them, but need this to be dinamic, so what i´m trying is to select all content from table 'body' where FIELD name like ´body%'
I understand what you're trying to do (or at least I think I do). The answer is simple. You can't do it.
Why not? Because it's nonsense. If you know the name of the table, you know the names of the fields (columns). Moreover, the WHERE clause is used for checking values in fields, not for checking field (column) names.
What you're actually trying to do is probably this:
SELECT [field_name] FROM body.
By the way, this sort of question should really be posted in the Application Development forum.

Similar Messages

  • How to rename the column field names

    hello guys,
    i am retrieving my field names from the database and i view it thru HTML.
    When i view it,the column names are those which are given while creating tables.
    Ex..
    fname,lname,phno,
    i want it as First Name,Last Name,Phone Number etc ...<%
    try {
         stmt = con.createStatement();
         sql="SELECT fname, lname, gender, email,phnum,sartweblink, sartaddress1, sartaddress2,sartcounty, country,sartpostcode,dob FROM Artist where artistid='" + sartid + "'";
         rs=stmt.executeQuery(sql);
         rsmd=rs.getMetaData();
         int colcount=rsmd.getColumnCount();
         for(i=1;i<=colcount;i++)
    %>
              <tr><td width="200"><FONT face=verdana size=2><%= rsmd.getColumnName(i)%>
    <%
    %>               </FONT>
        <font face=verdana size=2>
          <% while(rs.next())
              fname=rs.getString("fname");
              lname=rs.getString("lname");
              gender=rs.getString("gender");
              email=rs.getString("email");
               phnum=rs.getInt("phnum");
              weblink=rs.getString("sartweblink");
              address1=rs.getString("sartaddress1");
              address2=rs.getString("sartaddress2");
              county=rs.getString("sartcounty");
              country=rs.getString("country");
              postcode=rs.getString("sartpostcode");
               dob=rs.getString("dob");
          %>i make use of metadata..
    can anyone tell me how to do this..
    thanks in advance

    why not use alias:
    your query is
    SELECT fname, lname, gender, email
    and will be:
    SELECT fname FIRSTNAME, lname LASTNAME, gender GENDER, email EMAILADDRESS

  • Selecting using a field that stores a column_name to be used in the where

    I have a table REPORTING_CRITERIA with fields and field values:
    gl_criteria1 = 'cc.segment5'
    from_value1= '1123'
    to_value1= '1130'
    gl_criteria2 = 'cc.segment5'
    from_value2 = '1140'
    to_value2 = '1150'
    I am trying to run a select where I pull records where the actual field name stored in gl_criteria1 and gl_criteria2 is used in the where clause.
    ie.
    select bal.gl_balance, account_code
    from gl_balances bal, accounts cc, reporting_criteria crit
    where crit.report_name ='BUDGET'
    and crit.gl_criteria1 between crit.from_value1 and crit.to_value1
    What I want is to have the where read like:
    where crit.report_name ='BUDGET'
    and cc.segment5 between crit.from_value1 and crit.to_value1
    Thus cc.segment5 is the value stored in the reporting_criteria table in the gl_criteria1 field but it is an actual db column to be used in my select.
    How can I get this query to work so that the contents of gl_criteria1 field are actually read like a column name in my where?
    Edited by: ajgolden87 on Nov 8, 2012 11:10 AM

    Hi,
    You should know the column names of the table you are quering. If so you can make queries like this:
    with CC as
    select 1 id, 1123 segment5 from dual union all
    select 2 id, 1124 segment5 from dual union all
    select 3 id, 1125 segment5 from dual union all
    select 4 id, 1126 segment5 from dual union all
    select 5 id, 1127 segment5 from dual union all
    select 6 id, 1128 segment5 from dual union all
    select 7 id, 1129 segment5 from dual union all
    select 8 id, 1130 segment5 from dual union all
    select 9 id, 1131 segment5 from dual union all
    select 10 id, 1132 segment5 from dual
    ,REPORTING_CRITERIA  AS
    SELECT
      'SEGMENT5'        GL_CRITERRIA_1
      ,'1123'           FROM_VALUE_1
      ,'1130'           TO_VALUE_1
      ,'ID'             GL_CRITERRIA_2
      ,'4'              FROM_VALUE_2
      ,'7'              TO_VALUE_2
    FROM
      DUAL
    SELECT
      cc.*
    FROM
      CC
      ,REPORTING_CRITERIA
    WHERE
      GL_CRITERRIA_1 IS NULL
      OR CASE WHEN GL_CRITERRIA_1 = 'SEGMENT5' THEN SEGMENT5
              WHEN GL_CRITERRIA_1 = 'ID' THEN ID
              ELSE NULL END BETWEEN FROM_VALUE_1 AND TO_VALUE_1
      ) AND
      GL_CRITERRIA_2 IS NULL
      OR CASE WHEN GL_CRITERRIA_2 = 'SEGMENT5' THEN SEGMENT5
              WHEN GL_CRITERRIA_2 = 'ID' THEN ID
              ELSE NULL END BETWEEN FROM_VALUE_2 AND TO_VALUE_2
    ID SEGMENT5
    4     1126
    5     1127
    6     1128
    7     1129 Regards,
    Peter

  • Problem using alias field names in a sql query

    Hello,
    I have a question regarding a simple Oracle database SQL query writeup:
    In the following (badly written but properly working) SQL query:
    Query 1:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    (soe.field5 - (soe.field2 + soe.field3)) as field6,
    (select comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 1:
    I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
    Query 2:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6, <<< field4 does not work here
    (select
    comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select
    soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 2:
    Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
    Query 3:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6,
    soe.field7* (select comp.parValue from CompTable comp) as parValue1,
    soe.field8 - (parValue1*soe.field7+ soe.field9) as field10      <<<< parvalue1 does not work here
    parValue1*soe.field9 as TaxCondition               <<<< parvalue1 does not work here
    from
    SomeTable soe
    See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
    I will appreciate if you can guide me in the right direction on this issue.
    Thanks and Regards
    Rama

    SELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
    FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
    FROM TASK_DELEGATION t
    INNER JOIN COST_CODE c
    ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
    INNER JOIN Labour.dbo.LABOURALLOT l
    ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
    GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
    ) tmp

  • Prepared statement problem using a field name that contains a "?"

    I am attempting to execute the following query via use of a PreparedStatement:
    select [Spread_By_Cost_Center?], Debit_Category, Credit_Category, Start_Date, End_Date, Allocation_Type From ALLOCATION_FORMULA Where FormulaID = ?
    The query fails with the following message:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT
    field incorrect
    However, I can run this query directly in MS-ACCESS, using a value for the substitution parameter (i.e., FormulaID = 1)
    If I remove the "Spread_By_Cost_Center? field from the query within the PreparedStatement, the PreparedStatement query executes successfully.
    So, it would appear that the "?" in the field name is possibly being treated as a substitution parameter. Is this a bug within PreparedStatement? I do not want to use a Statement object, as the PreparedStatement provides a much more elegant solution (when it works).
    Any suggestions?

    That may be so, but as I see it there are two alternatives:
    1. Wait for the "bug" to be fixed.
    2. Change the database to use less problematic column names.
    I know which alternative I would choose.

  • Problem with column/field names in Oracle resultset being UPPERCASE

    Hi everyone,
    I understand that Oracle DBMS returns all the field names in UPPERCASE in the result set. However this is undesired for my application and I was wondering if there is any workaround for getting the field names in the application in exactly the same format as your select query. Is there any set method which can be called before to control this behavior.
    E.g. select ename as employeename from table_name;
    ORACLE RETURNS --> EMPLOYEENAME
    Required --> employeename
    Please help me
    ..Vinit

    Vinit,
    You can use column aliases in your query -- see Oracle SQL Reference for more details.
    Then you can set some connection property in Oracle JDBC that allows you to obtain the column alias (I think). Check the Oracle JDBC User's Guide and Reference for more details.
    Good Luck,
    Avi.

  • Using table field name as a variable

    Hi ,
    Is it possible to map some values to a field in a Ztable , if I have the field name of the Ztable in a variable.
    For ex:
    I have a ZTABLE -- which has some fields - ZF1 and ZF2.
    In my code, I determine the field in which I want to put data at runtime. For ex, in my code i determine at runtime I want to update field ZF2 , but I have this field name in a variable <V_FIELDNAME>
    So, Is it possible to do something as:
    <V_FIELDNAME> = ZF2.
    ZTABLE-<V_FIELDNAME>    =    <VARIABLE -SOME VALUE>.
    and this value should actually maps to ZTABLE-ZF2.
    If it is possible , how to do it ?
    Thanks-

    Hi Tamas,
    Thanks a lot for ur post ! it did certainly help. However, I need some more help.
    Here is what I need -
    I will have a string coming up from an interface which would be something like : Val1;Val2;Val3
    And in SAP R/3 I have a variable maintained as : Field1;Field2;Field3
    Field1 Field2 and Field3 are fields of a ZTABLE.
    So , at runtime, using the variable I have to determine which Value goes to which field and then insert this field in ZTABLE.
    So, ultimately , code should perform the following actions:
    ZTABLE-FIELD1 = Val1
    ZTABLE-FIELD2 = Val2
    ZTABLE-FIELD3 = Val3
    Insert ZTABLE.
    Going by code you provided, I can assign individual values, But then ultimately I need to map it to a structure which can be used to insert in a DB table. How can I do this?
    Thanks-

  • Can I use a field name in text module

    Hi,
    I get a object name of the standard text in a field.  Can I use that field in Text module.
    Thanks,
    Srinivas.

    Go to t-code SMARTFORMS->Text Module->Create or Edit-> choose add icon and type your field name (used in your smartform) like this &fieldname&, then use this Text module in your smartform.

  • Dynamic Selection using Summarization Fields Missing in TCODE CN43N

    If Using TCODE CN43 I can select using Summarization Fiields from PSMERK via Dynamic Selections.
    However, when I use TCODE CN43N the "Summarization Fields" node is not displayed.
    Does anyone know if it is possible to activate this option for CN43N.

    Hi,
    Please refer sap note 679705.
    hope it will be helpful
    thanks
    abdul

  • Select using Indexed field, still using sequential read

    Hi Experts,
    I am selecting from CATSDB table
    SELECT SINGLE *  FROM catsdb
              WHERE belnr = var.
    BELNR is indexed so I am expecting that this statement will do a direct read.
    But when this statement is run, SAP message indicates that
    it is performing a sequential read.  Anybody knows why this is?  And how do I make direct read happen?
    Thank you very much for your help.
    Bes Regards,
    Rose

    Hi,
    may be you need to update the database statistics for that table or you need to recreate the index. Check out db02 for the table or make some check using se14.
    regards
    Siggi
    PS: Also fm rsdu_analyze_tables will be of some help. do a test run in se37 and enter the name of the table.
    Message was edited by:
            Siegfried Szameitat

  • Grouping Using Partial Field Name

    I'm thinking that a substring function is the answer to your question: http://www.postgresql.org/docs/9.3/static/functions-string.html
    It's a little hard to tell without seeing the query though. Can you post the text with comments on what part you're having trouble with?

    This question is for those who know anything about creating a report in Crystal Reports.
    I'm modifying a report to show data where the filed "Customer Name" matches the specified criteria. Now I'm trying to see if I can group the data based off the first 12 characters of the field as that part is the same and the rest of the characters after that are different. 
    This topic first appeared in the Spiceworks Community

  • Get year from user selected month in field name

    Hi BExperts,
    I would your help about this problem on BI 7 :
    At the opening of the query, user selects a month (for example 03.2007).
    From this month, i have to indicate key figures on the selected month (03.2007) and key figures on the corresponding year (here 2007).
    I'm using a variable in order to get the selected month (0I_CMNTH).
    I don't know how to get the corresponding year (with a variable) ?
    For example : user selects "03.2007", in the query i would have :
    Period  Key figure
    03.2007     17
    2007           38
    Thanks for help.
    Points will be assigned.
    Cheers,
    Vince.

    Hello,
             I am not sure about the one you mentioned but this is another way which you can try by creating the customer exit variable V_YEAR under 0calyear characteristic and add the following code for gettting the previous year.
    data: year(4) type n,
             year1(4) type n.
    when 'V_YEAR '.
    if i_step = 2. "after the popup
    loop at i_t_var_range into loc_var_range
    where vnam = '0I_CMNTH'.
    year = loc_var_range-low (4).
    year1 = year - 1.
    clear l_s_range.
    l_s_range-low = year1.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'EQ'.
    append l_s_range to e_t_range.
    exit.
    endloop.
    endif.

  • Using a field hierarchy for selecting checkboxes?

    I have a bunch of checkboxes in a PDF that are dynamically added to the PDF during its creation process. Each checkbox is a cell in a table, and I do not know the number of rows or columns that will be in the PDF beforehand. What we are trying to do is add a header row to the table that allows the users to select/unselect all the check boxes in a column at once. I figured I could use the field name hierarchy approach to select/unselect all the checkboxes as long as I named them appropriately but I appear to be missing something.
    Take for example this table (assume [] denotes where a checkbox will go):
    Title
    Category 1
    Category 2
    [check.global.category1]
    [check.global.category2]
    Some Product
    [check.category1.cell1]
    [check.category2.cell1]
    Another Product
    [check.category1.cell2]
    [check.category2.cell2]
    What I would like to do is add a JavaScript call so that when check.global.category1 is clicked I could add something like this to the click event:
    var field = getField("check.category1");
    field.checkThisBox() //or checkThisBox(false);
    And that would toggle all the check boxes in the Category 1 column. However, that does not appear to work. Is there another mechanism to do this, or some way I can loop over all the check boxes that belong to the same hierarchy? I know this approach works with buttons and text fields but checkboxes appear to be different.

    I found the answer. To get all the checkboxes use getArray() after calling getField.
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/w whelp.htm?context=Acrobat9_HTMLHelp&file=JS_API_AcroJS.88.744.html

  • Using field names stored in the database in a query

    Hi,
    I'm working on a database that has field names stored in tables. In order to construct a query using the field names stored in the table, normally I'd use dynamic SQL. 
    For example in table1 I have
    Field_Name Value
    Field1
    'Name'
    Field 2
           'Address'
    I want to build a select statement  "SELECT Name, Address, FROM tblCustTable" - if possible not using dynamic SQL.
    Is there a neat way to do this?
    Thanks very much.
    Sad old developer

    No, it is not possible to dynamically include ANY object names (Columns, Tables, Functions, Procedures, etc) in SQL without using Dynamic SQL.
    The closest you can get, if you are choosing from a known set of names, is to use CASE statements:
    SELECT CASE
    WHEN t1.Field1='Name' THEN ct.[Name]
    WHEN t1.Field1='Address' THEN ct.[Address]
    END AS Field1
    FROM tblCustTable ct
    CROSSJOIN table1 t1
    WHERE ...
    However there are several disadvantages to this approach, and the SQL will quickly get very convoluted and difficult to maintain.   Dynamic SQL is much cleaner.
    -Tab Alleman

  • Substitution Variable for Field Name - Use in LOV Defintion

    Hi,
    I need to build an application with a lrage number of fields based on an LOV (Select List). All the LOVs will be sourced from a single table:
    LOOKUP_TYPE VARCHAR2(30)
    LOOKUP_CODE VARCHAR2(30)
    MEANING VARCHAR2(100)
    Each field will therefore need a simple LOV of:
    select lookup_code, meaning
    from
    app_lookups
    where
    lookup_type = 'LOOKUP_TYPE_NAME'
    order by 2Not complicated but it will take a long time due to the number of fields (across many pages).
    I would like to be able to have the same code for all fields. Something like:
    select lookup_code, meaning
    from
    app_lookups
    where
    lookup_type = V('THIS_FIELDS_NAME')
    order by 2With this code I could simply copy fields around and rename them - the LOVs would automatiically select the right values by using the Field Name to find the correct codes.
    A long shot - but worth asking.
    Any thoughts?
    Thanks,
    Martin

    Hi Andy,
    Yes I know about Shared Component LOVs but this does not address my issue. I am also not restricting based on a page item value. I just want to restrict dynamically based on the field name.
    On a page I will have at least 30 items, each with their own LOV. I can define an LOV for each item (either directly or though shared components) but each needs to be individually coded (where lookup_type = 'XXXX' with XXXX being different for every field).
    If possible I would like to dynamically use the field name to select the group of lookup codes that I want - all fields could then have the same code (or potentially the same Shared Component LOV).
    Not a major issue, but it would make my life a lot easier!!
    Martin

Maybe you are looking for

  • How do I get additional iMovie Themes?

    Is there any way to get or make additional themes for iMovie 6? I particularly like the Brushscript them in iDVD, but this is not one of the themes that comes with iMovie. Is there a way to modify the iDVD theme for iMovie, or to make a similar one f

  • I have a strange question...

    can i attach my (brand new) MacBook to my old iMac G3 with an ethernet cable and get internet on the G3? my macbook is hooked up to an AEBS(N) but my G3 doesnt have internet. here's a diagram. ...........(ethernet cable) iMac G3<--------->Macbook ...

  • Fixing size of objects

    Hi, I'm new with PE 6 and I'm trying to passport picture in which the the whole picture has to have a certain size, which is "easy" selecting the size on the printer, however the top part of it has to have a space of 5 mm between the top of the head

  • Question on Runtime TID and MSDID

    hi all, I have been researching the cor-relation between TID > MSGID and IDOC created on backend system. How can i corelate all of them and say that a particular TID is related to MSGID and "a" particular IDOC on the R/3 side. I would also like to kn

  • Safari/Firefox will not connect to websites.  BUT Entourage works normal.

    For the past 2 weeks both my iMac and MacBook Pro have experienced the same problem. Neither can connect to a website via Safari or Firefox BUT both send/receive email from Entourage. When i troubleshoot the Airport it says all is working properly. T