Jnerocorp Posted September 27, 2009 Share Posted September 27, 2009 Hello, I am trying to ONLY display the row pin from table pins with the highest id here is the code that i have so far <?php mysql_connect("mysql2.000webhost.com", "a4428795_admin2", "sc55207") or die(mysql_error()); mysql_select_db("a4428795_payment") or die(mysql_error()); $query = "SELECT pin, MAX(id) FROM pins GROUP BY pin"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "The highest id is ". $row['MAX(id)']. " and has pin number: " .$row['pin']; echo "<br />"; } ?> it displays this The highest id is 1 and has pin number: testkey1 The highest id is 2 and has pin number: testkey2 The highest id is 3 and has pin number: testkey3 The highest id is 4 and has pin number: testkey4 The highest id is 5 and has pin number: testkey5 Link to comment Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 If you're only picking 1 record from the database there's no need to create a loop. Additionally you should take advantage of ordering and limiting. $query = "SELECT pin, id FROM `pins` ORDER BY id DESC LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "The highest id is " . $row['id'] . " and has pin number: " . $row['pin']; Link to comment Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 that works perfectly now how do i make it so that it deletes that pin and id number out of the table Link to comment Share on other sites More sharing options...
Zane Posted September 27, 2009 Share Posted September 27, 2009 You already have a thread on this here http://www.phpfreaks.com/forums/index.php/topic,270770.msg1277702.html#msg1277702 Link to comment Share on other sites More sharing options...
Recommended Posts