Solved

display last entry(mysql/php)

Posted on 2003-10-21
6
802 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
Comment Utility
If its easeir it would be ok to place  the text boxes displaying the last entry below in rows
0
 

Author Comment

by:srima
Comment Utility
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
Comment Utility
So what syntax will it understand (unique id) , how do i give it a unique id?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 14

Accepted Solution

by:
ThG earned 155 total points
Comment Utility

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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now