get selected column value for the last row in oracle db

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boss1
    New Member
    • Sep 2007
    • 45

    get selected column value for the last row in oracle db

    hi all'

    i m using php4 and oracle 9idb for my web-application.

    i have got a problem .that is i just want to know how to get selected column value for the last row in table.

    suppose i have employee table having 10 rows and 8 columns.Now i want to get the value for :column1,column 5,column8 for the 10th(last row) no.of row.

    How to do this in oracle,php..can anybody help me?

    thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Easiest solution is to SELECT with a DESC ORDER BY. That way the last row will be the first one in the result set.

    However, assuming you have not done a DESC order by, you can fetch all rows into an array and read the last row. Like[php]$norows = oci_fetch_all($ statement, $results);
    if ($norows > 0) {
    $lastrow=$norow s-1; // last row = no of rows - 1
    $val1=$results[$lastrow][0]; // column 1
    $val5=$results[$lastrow][4]; // column 5
    $val8=$results[$lastrow][7]; // column 8
    }[/php]Ronald

    Comment

    • boss1
      New Member
      • Sep 2007
      • 45

      #3
      hi ,thank you for ur response.

      but the code does not showing any output.
      i wanted to show last row value for selective column by using"echo"
      But it does not show any result.[php]$query5 = "SELECT * FROM depo_location_t bl";
      $statement = ociparse ($c, $query5);
      ociexecute ($statement);
      $norows = ocifetchstateme nt($statement, $results);
      if ($norows > 0) {
      $lastrow=$norow s-1; // last row = no of rows - 1
      $val1=$results[$lastrow][0]; // column 1
      $val5=$results[$lastrow][4]; // column 5
      $val8=$results[$lastrow][7]; // column 8
      }
      echo"$val1";
      echo"$val5";
      echo"$val8";[/php]it does not give any output.
      so can u plz..help in this problem.
      Last edited by ronverdonk; May 6 '08, 10:42 PM. Reason: code tags!!

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        WARNING:
        Please enclose your posted code in [code] tags (See How to Ask a Question).

        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

        Please use [code] tags in future.

        MODERATOR

        Comment

        • boss1
          New Member
          • Sep 2007
          • 45

          #5
          hi ,thank you for ur response.

          but the code does not showing any output.
          i wanted to show last row value for selective column by using"echo"
          But it does not show any result.
          [php]$query5 = "SELECT * FROM depo_location_t bl";
          $statement = ociparse ($c, $query5);
          ociexecute ($statement);
          $norows = ocifetchstateme nt($statement, $results);
          if ($norows > 0) {
          $lastrow=$norow s-1; // last row = no of rows - 1
          $val1=$results[$lastrow][0]; // column 1
          $val5=$results[$lastrow][4]; // column 5
          $val8=$results[$lastrow][7]; // column 8
          }
          echo"$val1";
          echo"$val5";
          echo"$val8";[/php]
          it does not give any output.
          so can u plz..help in this problem.
          Last edited by ronverdonk; May 7 '08, 08:45 AM. Reason: warning: code tags !!!

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            THIS IS THE LAST WARNING:
            Please enclose your posted code in [code] tags (See How to Ask a Question).

            This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

            Please use [code] tags in future.

            MODERATOR

            Comment

            Working...