Solved

display last entry(mysql/php)

Posted on 2003-10-21
6
809 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.

617 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