?
Solved

how to get the latest/last record/row in mdb database with odbc connection.

Posted on 2009-05-02
20
Medium Priority
?
1,076 Views
Last Modified: 2013-12-12
how to get the latest/last record/row in mdb database with odbc connection.

like we use max in mysql , what we need to use here?
0
Comment
Question by:designersx
  • 12
  • 8
20 Comments
 
LVL 3

Expert Comment

by:prachwal
ID: 24286206
use MySQL dialect and Pas Throught Query - its very fast
0
 
LVL 3

Expert Comment

by:prachwal
ID: 24286210
or lin mysql table in Access -> right click and link menu or File -> Get External Data

You should create file ODB Connection and install MySQL ODBC Driver on PC with Access
0
 

Author Comment

by:designersx
ID: 24286263
sir sorry to say i really can't understand it.

i think u got me wrong. my question is this. please explain in detail.

How do I get the last  id from a database using a ODBC connection?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:designersx
ID: 24286267
i am using mdb as database.
0
 

Author Comment

by:designersx
ID: 24286302
I have a table (simple example):

ID Name Form Date
2 Bob 45 2005-6-23
3 Jim 42 2005-6-24
3 Bob 41 2005-6-28
2 Jim 47 2005-6-29

I need to query for the latest row by Date for each ID like 2 Jim
0
 
LVL 3

Expert Comment

by:prachwal
ID: 24286398
max id

SELECT tabela_a.date, Max(tabela_a.ID) AS MaxOfID
FROM tabela_a
GROUP BY tabela_a.date;


last id

SELECT tabela_a.date, Last(tabela_a.ID) AS LastOfID
FROM tabela_a
GROUP BY tabela_a.date;
0
 

Author Comment

by:designersx
ID: 24286553
thanks


above is working but in the lastquery error is coming ,why?

Warning: odbc_result() [function.odbc-result]: Field id not found in C:\wamp\www\fantaay\addquery.php on line 24

$con=odbc_connect('root','','');
$sql="insert into tbldistributor(distributor,address,city,zip,phone,fax,mobile,email,companyname) values('$distributor','$address','$city','$zip','$phone','$fax','$mobile','$email','$companyname')";
odbc_exec($con, $sql);
 
 
 
 
$con2=odbc_connect('root','','');
$sql2="select max(tblcountry.id) from tblcountry";
$row=odbc_exec($con2, $sql2);
while(odbc_fetch_row($row)){
	echo $id=odbc_result($row,"id");
}

Open in new window

0
 
LVL 3

Expert Comment

by:prachwal
ID: 24286611
maby
$sql2="select max(tblcountry.id) as id from tblcountry";
0
 

Author Comment

by:designersx
ID: 24286631
thanks it works.
0
 

Author Comment

by:designersx
ID: 24286778
what is the meaning of this error.
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver]Invalid use of null pointer , SQL state S1009 in SQLExecDirect in C:\wamp\www\fantaay\edit.php on line 15
 
Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in C:\wamp\www\fantaay\edit.php on line 17

Open in new window

0
 

Author Comment

by:designersx
ID: 24286784
this error also,
odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in C:\wamp\www\fantaay\edit.php on line 15

Open in new window

0
 
LVL 3

Expert Comment

by:prachwal
ID: 24286795
show SQL
0
 

Author Comment

by:designersx
ID: 24286858
error os at 15 line

278
select * from tbldistributor where distributorid='78'

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in C:\wamp\www\fantaay\edit.php on line 15

<?php 
	echo $countryid=$_REQUEST['countryid'];
	echo $distributorid=$_REQUEST['distributorid'];
?>
<form action="editquery.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $distributorid; ?>" method="post" name="edit">
<table width="272" border="1">
  <tr>
    <td colspan="2" align="center"><b>Edit Distributors Form</b></td>
  </tr>
 <?php
    
  	$con=odbc_connect('root','','');
	echo $sql="select * from tbldistributor where distributorid='".$_REQUEST['distributorid']."'";
	
	echo $rs=odbc_exec($con, $sql);exit;
	
	while (odbc_fetch_row($rs))
	{
  ?>
    
  <tr>
  <td>Distributor</td>
  <td><input type="text" name="distributor" value="<?php echo $distributor=odbc_result($rs,"distributor"); ?>"></td>
  </tr>
  
  <tr>
  <td>Address</td>
  <td><input type="text" name="address" value="<?php echo $address=odbc_result($rs,"address"); ?>"></td>
  </tr>
  
  <tr>
  <td>City</td>
  <td><input type="text" name="city" value="<?php echo $city=odbc_result($rs,"city"); ?>"></td>
  </tr>
  
  <tr>
  <td>Zip</td>
  <td><input type="text" name="zip" value="<?php echo $zip=odbc_result($rs,"zip"); ?>"></td>
  </tr>
  
  <tr>
  <td>Phone</td>
  <td><input type="text" name="phone" value="<?php echo $phone=odbc_result($rs,"phone"); ?>"></td>
  </tr>
  
  <tr>
  <td>Fax</td>
  <td><input type="text" name="fax" value="<?php echo $fax=odbc_result($rs,"fax"); ?>"></td>
  </tr>
  
  <tr>
  <td>Mobile</td>
  <td><input type="text" name="mobile" value="<?php echo $mobile=odbc_result($rs,"mobile"); ?>"></td>
  </tr>
  
  <tr>
  <td>Email</td>
  <td><input type="text" name="email" value="<?php echo $email=odbc_result($rs,"email"); ?>"></td>
  </tr>
  
  <tr>
  <td>Company Name</td>
  <td><input type="text" name="companyname" value="<?php echo $companyname=odbc_result($rs,"companyname"); ?>"></td>
  </tr>
  
  <?php
  }
  ?>
  <tr>
    <td align="center"><input name="edit" type="submit" value="edit"></td>
    <td align="center"><input name="Cancel" type="submit" value="Cancel" onClick="window.location.href='snap.php'"></td>
  </tr>
</table>
</form>

Open in new window

0
 
LVL 3

Accepted Solution

by:
prachwal earned 400 total points
ID: 24286893
are ypu shure takt distributorid column exist in tbldistributor table?
0
 

Author Comment

by:designersx
ID: 24287116
there  is not distributorid in tbldistributor table
0
 
LVL 3

Expert Comment

by:prachwal
ID: 24287140
if You chcech non exist column Access Want a parametr
0
 

Author Comment

by:designersx
ID: 24287229
i have a id column in tbldistributor.
please tell me where do i need to make editions.

what is this chcech?
0
 
LVL 3

Expert Comment

by:prachwal
ID: 24287285
tray this
$sql="select * from tbldistributor where tbldistributor.id='".$_REQUEST['distributorid']."'";

chcech -> chceck my mistake, sory
0
 

Author Comment

by:designersx
ID: 24287293
thanks solved the problem, yes u r right there was a problem of field name.
0
 

Author Comment

by:designersx
ID: 24288744
sir when i am uploading my files and mdb database on server , server is not picking the database.why is it so?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question