0

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

2
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by stonest123
0

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

Edited by pritaeas: n/a

0

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

Edited by stonest123: n/a

1

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).

0

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

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

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

Edited by stonest123: n/a

1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.