Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

display last entry(mysql/php)

Posted on 2003-10-21
6
Medium Priority
?
811 Views
Last Modified: 2013-12-12
Using php/html/mysql,  I'm trying create web page that on one side (left colum) a user can enter information into a MySQL db (which i have been succesful at) and on the other side (right colum) there are text boxes displaying the last entry into the db, how can this be done?
0
Comment
Question by:srima
  • 3
  • 2
6 Comments
 

Author Comment

by:srima
ID: 9596720
If its easeir it would be ok to place  the text boxes displaying the last entry below in rows
0
 

Author Comment

by:srima
ID: 9596747
Perhaps i should have posted my code and been more specific as to where my problem is -

<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="cattle_eyci.php">
<table>
  <tbody>
    <tr>
      <td><input type="text" name="QDATE">  </td>
      <td><input type="text" name="AMOUNTVAR">  </td>
        <td><input type="text" name="AMOUNT">  </td>
    </tr>
      <tr>
      <td><input type="submit" value="save data">  </td>
    </tr>
    <tr>
      <?PHP
$DBhost = "localhost";
$DBuser = "name";
$DBpass = "password";
$DBName = "database";
$table = "table";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
//unique_id

$sqlquery = "SELECT * FROM $table ORDER BY uniqid DESC LIMIT 0,1";
$result = mysql_query($sqlquery) or die(mysql_error().$sqlquery);

$number = mysql_num_rows($result);
$i = 0;

if ($number < 1) {
print "<CENTER><P>There Were No Results for Your Search</CENTER>";
}
else {
while ($number > $i) {
$date = mysql_result($result,$i,"QDATE");
$amount = mysql_result($result,$i,"AMOUNT");
$amount_v = mysql_result($result,$i,"AMOUNTVAR");

print "<td><b>date:</b> </td><td><input value=$date></td></tr><tr><td><b>amt:</b> </td><td><input value=$amount></td></tr><tr><td><b>amt_v:</b> </td><td><input value=$amount_v></td></tr><br>";
$i++;
}
}
?>
    </tr>
  </tbody>
</table>
</form>
</body>
</html>

the error message i get is Unknown column 'unique_id' in 'order clause'SELECT * FROM CATTLE_EYCI ORDER BY uniqid DESC LIMIT 0,1

i got --$sqlquery = "SELECT * FROM $table ORDER BY unique_id DESC LIMIT 0,1";-- from another site  saying this was how you display the entry in a database table
What do i have to change, i an't seem to find info about this anywhere. pls help
0
 

Author Comment

by:srima
ID: 9596778
So what syntax will it understand (unique id) , how do i give it a unique id?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Accepted Solution

by:
ThG earned 620 total points
ID: 9597056

change your table structure to add:

unique_id unsigned not null unique auto_increment

then when you add rows to your table supply unique_id as 0, and it will automatically be set to a sequential number.
0
 

Expert Comment

by:design2odd
ID: 9608210
set up an autonumber field. then when your users make a new entry it will have the highest value.

the you query the db

$query = "SELECT MAX(Table.uniqueID) AS MaxValue FROM Table";

And bang you have your max number then you can use that to pull all records with that ID
0
 

Expert Comment

by:design2odd
ID: 9608224
Here is an example

$query = "SELECT MAX(Article.articleID) AS crapFace FROM Article";
$result = mysql_query($query) OR die("MySQL Error " . mysql_errno() . ": " . mysql_error());
$myrow = mysql_fetch_array($result);

$query2 = "SELECT * FROM  Article WHERE articleID = '$myrow[crapFace]'";
$result2 = mysql_query($query2) OR die("MySQL Error " . mysql_errno() . ": " . mysql_error());
$myrow2 = mysql_fetch_array($result2);

Hope it helps
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question