Web Analytics Made Easy -
StatCounter Displaying last entry - CodingForum

Announcement

Collapse
No announcement yet.

Displaying last entry

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

  • Displaying last entry

    PHP Code:
    <?php
        
            $sql 
    "SELECT * FROM adddb WHERE id = '$_GET[id]'";
                
    $result mysql_query($sql$conn) or die(mysql_error());
                    while (
    $newArray mysql_fetch_array($result)) {
                    
                    
    $id $newArray['id'];
                    
    $nameof $newArray['nameof'];
                    
    $why $newArray['why'];    
        
        }
    ?>
    this what i got so far. How do i get it so it only displays last entry in to the database?

  • #2
    just add "ORDER BY feildname DESC" to the select statement,

    like:

    sql = "SELECT * FROM adddb WHERE id = '$_GET[id]' ORDER BY id DESC";

    -SiX

    Comment


    • #3
      Don't forget to put a "LIMIT 1" to it, otherwise it would select all rows with the specified id, although you only need the last row.

      dumpfi
      "Failure is not an option. It comes bundled with the software."
      ....../)/)..(\__/).(\(\................../)_/)......
      .....(-.-).(='.'=).(-.-)................(o.O)...../<)
      ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
      Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

      Comment


      • #4
        oh yah, I guess i didn't notice the loop. which you don't need if your only selecting one record. so insted of adding limit ( more code ), remove your loop code.

        Comment


        • #5
          Well, I thought more of optimizing the SQL statement. I wouldn't omit the "LIMIT 1", especially not for only saving 8 characters to write. (You can't be that lazy, can you?)

          dumpfi
          "Failure is not an option. It comes bundled with the software."
          ....../)/)..(\__/).(\(\................../)_/)......
          .....(-.-).(='.'=).(-.-)................(o.O)...../<)
          ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
          Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

          Comment


          • #6
            Thank You

            Comment

            Working...
            X