0

I have php form which I used to input Members Details of my system into the database. My requirement is to display the last member's 'member id' in a input box. When I try the following code it gives me the 'member id' of all the members in a select box. Please correct my php coding to display only the 'member id' of the last member.

php coding

  $dbcon = mysql_connect("localhost","root","root");
  $db = mysql_select_db("MemberDB",$con);

  $sqlselect = "SELECT MemID FROM Member" ;
  $result = mysqli_query($dbcon,$sqlselect);

html coding

<html>
    <head>
        <title>display the last member id</title>
    </head>
    <body>
        <select id="memid" name="memid1">  
            <option>Select Member ID</option>";
            <?php while($row = mysqli_fetch_array($result)):;?>
                <option><?php echo $row[1];?></option>";
            <?php endwhile;?>
        </select>       
    </body>
</html>

1 Answer 1

2

Try this SELECT query, this is from here:

SELECT MemID FROM Member
ORDER BY MemID DESC
LIMIT 1

This will order your data in descending order, then get the topmost data from that order.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.