denoteone Posted October 12, 2009 Share Posted October 12, 2009 $query = "SELECT * FROM prices ORDER BY 'countkey' DESC LIMIT 1"; $result = mysql_query($query)or die (mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); I need to get the last entry in a table and then echo it into text boxes. <div id="mocha_sm" ><input name="mocha_small" type="text" id="company" size=2 maxlength=5 value="<? echo $row['mocha_sm']; ?>"></div> But it only returns the entries in the first row. Does anyone see what I am doing wrong I think my issue is with the countkey field. I have it set to an INT and it auto increments Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/ Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 What does it mean 'last entry in a table'? Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935634 Share on other sites More sharing options...
denoteone Posted October 12, 2009 Author Share Posted October 12, 2009 countkey mocha_sm mocha_md mocha_lg icemocha_sm icemocha_md icemocha_lg lat_cap_sm lat_cap_md lat_cap_lg icelat_sm icelat_md icelat_lg coffee_sm coffee_md coffee_lg icecoffee_sm icecoffee_md icecoffee_lg hotchoc_sm hotchoc_md hotchoc_lg Edit 1 3.33 4.44 5.55 6.66 7.77 8.88 9.99 1.11 2.22 3.33 4.44 5.55 6.66 7.77 8.88 9.99 1.11 2.22 3.33 4.44 5.55 Edit 2 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 Edit 0 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 so judging by the entries above all the text fields should be 9.99 but I am still get the numbers from the first row. Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935636 Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 You're ordering descending on `countkey` column, which means you should get row with countkey 2 Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935638 Share on other sites More sharing options...
denoteone Posted October 12, 2009 Author Share Posted October 12, 2009 Rows countkey 1 0 1 1 1 2 when I look at the countkey this is what I am getting. Why are the Row's not incrementing? Could this be my issue? Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935654 Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 I don't know what 'Rows' is supposed to be. If you need a row with `countkey` 0 as first, order by countkey ASC Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935656 Share on other sites More sharing options...
denoteone Posted October 12, 2009 Author Share Posted October 12, 2009 Thank you for being patient. Here is another example with a new row added to the database. countkey mocha_sm mocha_md mocha_lg icemocha_sm icemocha_md icemocha_lg lat_cap_sm lat_cap_md lat_cap_lg icelat_sm icelat_md icelat_lg coffee_sm coffee_md coffee_lg icecoffee_sm icecoffee_md icecoffee_lg hotchoc_sm hotchoc_md hotchoc_lg 1 3.33 4.44 5.55 6.66 7.77 8.88 9.99 1.11 2.22 3.33 4.44 5.55 6.66 7.77 8.88 9.99 1.11 2.22 3.33 4.44 5.55 2 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 8.88 3 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 9.99 4 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 when I query the data base I want to get the final row which is "4 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22 2.22" and I want to all of the entries of the different fields by $query = "SELECT * FROM prices ORDER BY 'countkey' DESC LIMIT 1"; $result = mysql_query($query)or die (mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); that way i can echo them into text fields. <div id="mocha_sm" ><input name="mocha_small" type="text" id="company" size=2 maxlength=5 value="<? echo $row['mocha_sm']; ?>"></div> <div id="mocha_sm" ><input name="mocha_small" type="text" id="company" size=2 maxlength=5 value="<? echo $row['mocha_md']; ?>"></div> <div id="mocha_sm" ><input name="mocha_small" type="text" id="company" size=2 maxlength=5 value="<? echo $row['mocha_lg']; ?>"></div><div id="mocha_sm" ><input name="mocha_small" type="text" id="company" size=2 maxlength=5 value="<? echo $row['mocha_sm']; ?>"></div> etc....... Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935676 Share on other sites More sharing options...
Zane Posted October 12, 2009 Share Posted October 12, 2009 you've got 'countkey' in single quotes. The should be in between backticks... or better yet.. nothing at all. This being since it is a column in the table i.e SELECT * FROM prices ORDER BY `countkey` DESC LIMIT 1 or SELECT * FROM prices ORDER BY countkey DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/177452-only-get-first-row-not-most-recent-entry/#findComment-935720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.