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
Solved

display last entry(mysql/php)

Posted on 2003-10-21
6
806 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 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