Jump to content

Recommended Posts

Newbie here, I am actually a math teacher working on creating a simulated store front for my students where they keep up with inventory, budgeting etc.

 

Everyday my students will have to look at how much product is in stock, how much product was sold, and then input how much should be ordered for the next day.

 

I am working on an answer key that will be used to validate students input but the 'quantity' and 'sold' fields will be relative to the most recent post. Right now the code below pulls all the rows under 'quantity', but I need it to only pull the most recent post.

 

I have done my best to search the forum and try to find how to do this, but admittedly I am not even really sure what to be searching for. Any help would be great.

 

 

 

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("myDatabase", $con);

$result = mysql_query("SELECT * FROM myTable");

while($row = mysql_fetch_array($result))
  {
$quantity = $row['quantity'];
$sold = $row['numbersold'];
$needed = $row['remaining'];
echo $needed-($quantity-$sold);
  }

mysql_close($con);
?> 

Well I will be doing this for several tables, but the one I am working on right now only has 3 fields.

 

I have setup a field that automatically places the current time stamp, a field where the student lists the product they are ordering, and a field where the student inputs the amount they are ordering.

 

TimeStamp |  Product  |  Amount  |

 

I have been trying to fit into my code for it to sort out the max(Timestamp) and then limit 1.

 

Not sure how the ordering of a time stamp day by day, or week by week would work though... Also not sure if that is even the way to go about it, just all I have been able to find.

 

 

Thanks!

You may be able to break the timestamp down into its component parts, and then order the returning data according to those parts.  There's a whole bunch of date/time related functions you can use: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html  I'm just unsure if they're all compatible with a timestamp.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.