Solved

display last entry(mysql/php)

Posted on 2003-10-21
6
808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 14

Accepted Solution

by:
ThG earned 155 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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