Jump to content

Recommended Posts

$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

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.

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.......


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.