Jump to content

Temporary tables in sql


madhuramasamy

Recommended Posts

Iam trying to use temporary tables  to store data and make some changes to them. im getting

 

Parse error: parse error, unexpected T_STRING in select statement in the following code.

 

Thanks in advance..

 

 

<?php
include "basic.php";
include "header.php";
include "dbname.php";
select Chemical_ID, count(Chemical_ID) as stock into #instock from Chem_Inventory where Date_Out='0000-00-00' and (Chemical_ID>=5000 and Chemical_ID<6000);
//select Chemical_Name into #instock from Chemicals_waste where instock.chemid=Chemicals_waste.Chemical_ID;
$query="select * from #instock order by chemname ASC ";
$result=mysql_query($query);
print "<h3><p><center>Microlab Chemical Inventory</center></p></h3><br>";         
print "<table><tr><td><b>Chemical ID</td><td><b>Chemical Name</td><td><b>In Stock</td></tr>";
while ($sel = mysql_fetch_array($result)){
print "<tr><td>$sel[chemid]</td><td>$sel[chemname]</td><td>$sel[stock]</td></tr>";}
print "</table>\n";
drop table #instock;
?>

Link to comment
https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/
Share on other sites

What is this supposed to be?

select Chemical_ID, count(Chemical_ID) as stock into #instock from Chem_Inventory where Date_Out='0000-00-00' and (Chemical_ID>=5000 and Chemical_ID<6000);
//select Chemical_Name into #instock from Chemicals_waste where instock.chemid=Chemicals_waste.Chemical_ID;

 

You can't have SQL mixed with your PHP.

 

And I don't think using # in table names is such a good idea....

 

The error was on line 4

 

<?php
include "basic.php";
include "header.php";
include "dbname.php";
dbconnect("MICROLAB","MICROLAB","Charles1","web6.duc.auburn.edu");
select Chemical_ID, count(Chemical_ID) as stock into #instock from Chem_Inventory where Date_Out='0000-00-00' and (Chemical_ID>=5000 and Chemical_ID<6000);
$query="select * from #instock order by chemname ASC ";
$result=mysql_query($query);
print "<h3><p><center>Microlab Chemical Inventory</center></p></h3><br>";         
print "<table><tr><td><b>Chemical ID</td><td><b>Chemical Name</td><td><b>In Stock</td></tr>";
while ($sel = mysql_fetch_array($result)){
print "<tr><td>$sel[chemid]</td><td>$sel[chemname]</td><td>$sel[stock]</td></tr>";}
print "</table>\n";
drop table #instock;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.