I'm not sure if this belongs in PHP or in SQL forum but basically...
when using odbc_result_all, the bottom results is missed all the time, i don't know why it does this but i think its something to do with the driver. So, to get the last result from the query i have done, is there a way i can maybe sort the fields descending (so i get the last row first) and then print only that row out in a separate query from the one i use to obtain all the results from the database?

Thanks

Recommended Answers

All 8 Replies

If you want such a workaround than a simple UNION with a single row would be sufficient (assuming MySql):

SELECT * FROM mytable
UNION
SELECT * FROM mytable LIMIT 1

So, if i wanted to the last record of the database how would i go about getting it?
(As the amount of records per statement would change, or would i still need to sort descending?)
Thanks

My demo shows how to add one dummy record. If you use that construct your last result would be accessible by your loop (or however you do it).

ohhh i see now! If i show you my current statement and the loop could you show me how to apply it?

$postlocation = $_POST['t1'];
$postresponsible = $_POST['t2'];


$results="SELECT * FROM BackupLog WHERE 
Location = '$postlocation' 
AND Responsible = '$postresponsible'";

$rs=odbc_exec($conn, $results);
$last=odbc_exec($conn, $lastresult);

while (odbc_fetch_array($rs)){

$results2 = odbc_result_all($rs, "border=1");

echo $results2;

echo "</table>";	

}

Thats the code i use in order to run and loop out the statement

Thanks for your help

$results="SELECT * FROM BackupLog WHERE Location = '$postlocation' AND Responsible = '$postresponsible' UNION SELECT * FROM BackupLog LIMIT 1";

I'm now getting this error:

PHP Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

I did forget to mention its not mySQL its Access that I'm using, is there an equivalent?

Edit, also is there a script i can add to remove the row after it has been created, just so i don't start populating the database with dummy fields

I think this will work:

$results="SELECT * FROM BackupLog WHERE Location = '$postlocation' AND Responsible = '$postresponsible' UNION SELECT TOP 1 * FROM BackupLog";

This is just a select statement. Nothing is created in the database.

Thanks so much got it working now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.