combing field name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    combing field name

    hii guys i have a small problem
    i hve a filed called fname1,lname2 ......fname6,ln ame6 and pauthor which stores say 1..6 which says who is the author ...so is there any way to combine 2 field name like this fname.pAuthor ...so tht i get author name ....i am using php.
  • bilibytes
    New Member
    • Jun 2008
    • 128

    #2
    Originally posted by pradeepjain
    hii guys i have a small problem
    i hve a filed called fname1,lname2 ......fname6,ln ame6 and pauthor which stores say 1..6 which says who is the author ...so is there any way to combine 2 field name like this fname.pAuthor ...so tht i get author name ....i am using php.
    instead of putting "....." try to explain what you want with words, it would help to understand what your problem is in order to get a solution.

    if what you want is to get the values of the "fname" and "pAuthor" assuming they are on the same table, write:
    Code:
    $recordset = mysql_query('SELECT fname, pAuthor, FROM tablename', $link);
    (WHERE id=123): optional

    then from php simply get the row by looping the rows in your MySQL resource with:
    Code:
    $i=0;
    while($row = mysql_fetch_array($recordset)){
    $entire_names[$i] = $row['fname'].' '.$row['pAuthor'];
    $i++;
    }
    then you could print the $entire_name array content with
    Code:
    print_r($entire_names);
    if in your query you use the WHERE clause then you would not need to use the while(), that is: assuming you get one single record
    Just do:
    Code:
    $row = mysql_fetch_array($recordset);
    $entire_name = $row['fname'].' '.$row['pAuthor'];
    best regards

    bilibytes

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      hey tht "....." meant to say that upto fname6,thts its...
      Hey i want to do it in one query like
      select fname.pAuthor from table or
      select fname{pAuthor} from table is there any way of joining like this.....i store the number of the author in pAuthor field and if pAuthor says 1 then fname1 is the name of author

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        You question is unclear.

        Perhaps you should start with the number of tables you are interested in extracting data from, the exact structure of those tables and exactly what you are trying to retrieve (contents of the rows order of number of rows in the result set i.e. expecting 0 or 1 or many).

        At the moment it appears that you have a single table where pAuthor is one of the fields so your own code "select fname.pAuthor from table" should work fine.

        Please also remember that everyone on this site is volunteering they time and expertise for free, if they ask for more detail it is because what has been written so far has not made the problem clear to them.

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #5
          Originally posted by Banfa
          You question is unclear.

          Perhaps you should start with the number of tables you are interested in extracting data from, the exact structure of those tables and exactly what you are trying to retrieve (contents of the rows order of number of rows in the result set i.e. expecting 0 or 1 or many).

          At the moment it appears that you have a single table where pAuthor is one of the fields so your own code "select fname.pAuthor from table" should work fine.

          Please also remember that everyone on this site is volunteering they time and expertise for free, if they ask for more detail it is because what has been written so far has not made the problem clear to them.
          select fname.pAuthor from table is not working da...

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Have a look at CONCAT

            Comment

            • pradeepjain
              Contributor
              • Jul 2007
              • 563

              #7
              Originally posted by r035198x
              Have a look at CONCAT
              tried that also ..did not work .

              fname is just a string and pAuthor a field name and when i combine like fname.pAuthor
              it should become a field name like fname1,fname2

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Post what you tried that doesn't work.

                Comment

                • pradeepjain
                  Contributor
                  • Jul 2007
                  • 563

                  #9
                  select fname.pAuthor from abstract;

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Where is the CONCAT?

                    Comment

                    Working...