Link to home
Start Free TrialLog in
Avatar of TTCLIVE
TTCLIVE

asked on

Temp Table Query Problems

I have these two Access queries that I need to put in a PHP page. The problem is that i cannot figure out how to even get the page to load. I think it's a syntax problem, but this is the first time I've ever tried to use a temp table in Access or from a sql query outside of access. Can you help?


Access Queries:
SELECT AllInfo.* INTO tempTable
FROM AllInfo
WHERE AllInfo.Extension=[Enter Extension Number]
And AllInfo.Date=[Enter Date];
 
SELECT tempTable.Extension, tempTable.Date, tempTable.Time, tempTable.IO, tempTable.AC, tempTable.PhN, tempTable.Duration, (select max([Time]) from tempTable as A where A.Extension =tempTable.extension And  A.Time<tempTable.time and A.[Date]=tempTable.[Date]) AS Time2, format(nz([Time]-[Time2],0),"hh:nn:ss") AS ElapsedTime
FROM tempTable;
 
-------------------------------------------------------------------
PHP Page SQL queries
 
$sql0 = "SELECT * From AllInfo INTO tempTable WHERE Extension = '$ex' AND Date=#$id#";
 
$queryTempTable = "SELECT tempTable.Extension, tempTable.Date, tempTable.Time, tempTable.IO, tempTable.AC, tempTable.PhN, tempTable.Duration, (select max([Time]) from tempTable as A where A.Extension =tempTable.extension And  A.Time<tempTable.time and A.[Date]=tempTable.[Date]) AS Time2, format(nz([Time]-[Time2],0),"hh:nn:ss") AS ElapsedTime
FROM tempTable"
ORDER BY DateTime, Val(Left(Time,2)), Val(Right(Time,2));
 
$sql0 = odbc_exec($odbc,$sql0) or die(odbc_errormsg());   
$queryTempTable = odbc_exec($odbc,$queryTempTable) or die(odbc_errormsg());  
 
echo "<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"borderTable\"><tr><th class=\"borderTable\">   Extension   </th><th class=\"borderTable\">     Time     </th><th class=\"borderTable\">In/Out</th><th class=\"borderTable\">Phone Number</th><th class=\"borderTable\">Duration</th><th class=\"borderTable\">Duration</th></tr>";
 
while($row = odbc_fetch_array($queryTempTable)) 
{ 
echo "<tr>";
echo '<td class=\"borderTable\"><center>'.$row['Extension'].'</center></td class=\"borderTable\">'; 
echo '<td><center>'.date("h:i", strtotime($row['DateTime'])).'</center></td>';  
echo '<td class=\"borderTable\"><center>'.$row['IO'].'</center></td class=\"borderTable\">';
echo '<td class=\"borderTable\"><center>('.$row['AC'].') ';
echo ''.$row['PhN'].'</center></td class=\"borderTable\">';
echo '<td class=\"borderTable\"><center>'.$row['Duration'].'</center></td class=\"borderTable\">';
echo '<td class=\"borderTable\"><center>'.$row['ElapsedTime'].'</center></td class=\"borderTable\">';
 
} // end while

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TTCLIVE
TTCLIVE

ASKER

I fixed the queries with your code and changed the syntax, but I apparently cannot create the temptable in the database because it is read only. So I created a link database so that I can create the table in a separate database but still query the table I need to.

Then when I run the query, it tells me:

[Microsoft][ODBC Microsoft Access Driver] Cannot update. Database or object is read-only.

How do I make the database I created editable so I can run this, and what is the code to drop the table after I create it so I can run this whenever I need to?
DROP TABLE tempTable

The above is the syntax for dropping the table.  I don't believe I have had that issue, so I will check and see what I find.  In the meantime, you can double check database security settings and NTFS rights to the MDB file itself as with standard file and default security I usually connect to MDB files for read/write with no issues; however, it has been a while since can use SQL Express in place of Access these days.
Avatar of TTCLIVE

ASKER

I checked the NTFS permissions, and just in case while testing added "Everyone" and gave them All permissions.  

Do I need to preface that "DROP TABLE tempTable" with anything in a PHP page, or just drop it at the end of the page inside the "?>" ?

I still get the same error when trying to run the query to either create the temp table or drop it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TTCLIVE

ASKER

Okay, so once I get this working I will get the Drop Table working as well. Any ideas on how to allow access to create or drop a table in a link database without getting the "Database or object is read-only." error?
Avatar of TTCLIVE

ASKER

It's almost like it's trying to create the temp table in the main database, not the Link Database I created to run all the queries...is there a way to tell is to create the table in this link database rather than trying to do it in the actual database where it doesn't have permissions?
This should be trying to create the table in whichever database is connected to through the connection string from my understanding.
Avatar of TTCLIVE

ASKER

That's what I thought as well, but the database that I created and linked the tables to so that I could run queries is set in a folder that has NTFS permissions for Everyone set to All and there is no password on the database at all, and it still tells me the database is read only whenever I try to create the temp table.

I can run the query directly in Access, but not from an external page.  

So I'm back at square one with a query that works in access directly, but that I cannot run from a web page. Any other ideas on how to accomplish the same goal without trying to use a temp table anyone? Or maybe a way to specify where the temptable should be created?
Avatar of TTCLIVE

ASKER

I really need to get htis working, anyone have any ideas? I'm open to suggestions!!