
November 2nd, 2012, 06:27 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Location: Indiana
Posts: 3
Time spent in forums: 1 h 14 m 51 sec
Reputation Power: 0
|
|
|
PHP5 - MSSQL / mySQL not working as expected
Hello all... Thank you for your time in looking into my problem...I have some code that is not working as expected, I am trying to get the LAST record set from my DB and it seems to only get the first record. I am using the "Order by field desc" method.
this works correctly when I return ALL of the rows but not if I just want to get the first row (in this case the last row written)
Here is the code that I am using...
Note: there are 2 connections to the same DB here getting different records but have the same dbfield name
PHP Code:
// connect to a DSN "myDSN"
$conn1 = odbc_connect('dbname','uid','pw');
// the SQL statement that will query the database
$sqlcbn="select * from tablename where fieldkey=" .$row["id"]. " order by id desc";
// perform the query
$resul1t=odbc_exec($conn1, $sqlcbn);
// Check if there are records
if (odbc_num_rows($resul1t) != 0) {
// fetch tha data from the database
$nerd=odbc_num_rows($resul1t);
// echo $nerd;
while ($r1ow = odbc_fetch_array($resul1t))
{$shofield = $r1ow["dbfield"];}
}else{$shofield=$row["dbfield"];}
echo' <td>' .$shofield. ' </td></tr>';
|