Fetching Most Recent Record
Posted: Tue Aug 30, 2011 10:39 am
Yep, it's been asked before. But I'm running into problems...
Goal: Add a record then fetch the auto-incremented primary key column value to then query the database on the data just entered and do some math on it.
Flow: User enters data. Data inserted into database. Find "loadid" (auto-incremented primary key column name) of the record just entered. Call a function to do some math on this data. Return an array with final values.
The problem: I can get the "loadid" number just fine. But actually getting the row's data is failing for some reason. I'm probably just having a bad Tuesday...
Code:
$result prints as Resource ID #11. The stuff inside my while statement just doesn't happen.
Goal: Add a record then fetch the auto-incremented primary key column value to then query the database on the data just entered and do some math on it.
Flow: User enters data. Data inserted into database. Find "loadid" (auto-incremented primary key column name) of the record just entered. Call a function to do some math on this data. Return an array with final values.
The problem: I can get the "loadid" number just fine. But actually getting the row's data is failing for some reason. I'm probably just having a bad Tuesday...
Code:
Code: Select all
function load_analysis($type,$start,$end,$loadid)
{
echo "<br>Just entered analysis.<br>";
echo "<br>Type: " . $type . ".<br>";
echo "<br>Start: " . $start . "<br>";
echo "<br>End: " . $end . "<br>";
echo "<br>LoadID: " . $loadid . "<br>";
echo "<br>Checking type...<br>";
if ($type == "single") {
echo "<br>Type is single<br>";
$query = "SELECT * FROM loads WHERE 'loadid' LIKE '" . $loadid . "'";
echo "<br>Query: " . $query;
$result = mysql_query($query);
echo "<br>Result: " . $result . "<br>";
while($row = mysql_fetch_assoc($result)) {
echo "<br>Row: " . $row . "<br>";
echo "<br>BasicPayMethod:" . $row['basicpaymethod'] . "<br>";
.... Function continues but rest of it is irrelevant....