473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating TEMPORARY TABLES in mysql and accessing througth php script

4 New Member
<?php
/*
* Created on Apr 13, 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
require_once 'init.php';
$con=mysql_conn ect("localhost" ,"root","");
$dbc=mysql_sele ct_db(test,$con )or die("Database select error:" . mysql_error($co n));

$smarty->display('test. tpl');
//if(isset($_POST['btn_submit'])||($_GET['act'])!=''||($_GET['act21'])!=''||($_GET['act22'])!=''||($_GET['page'])!=''||($_GET['act23'])!=''||($_GET['act24'])!='')
if(isset($_POST['btn_submit']))
{
$qr="select * from temp where status='y'";
$user=mysql_que ry($qr);
$dr="drop TEMPORARY TABLE #temp1";
$redr=mysql_que ry($dr);
$qry2="CREATE TEMPORARY TABLE IF NOT EXISTS temp1 (`uid` INT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`user_name` VARCHAR(20) ,`email` VARCHAR(30),`fn ame` VARCHAR(20),`ln ame` VARCHAR(20))TYP E=ISAM";
$loc="LOCK TABLE temp1 WRITE";
$resl=mysql_que ry($loc);
$res2=mysql_que ry($qry2)or die ("Error in query: $qry2. ".mysql_error() );
while($rearr=my sql_fetch_array ($user))
{
$ro =$rearr[uid];
$un =$rearr[user_name];
$em =$rearr[email];
$fn =$rearr[fname];
$ln =$rearr[lname];
//echo $qry4 ="INSERT INTO `#temp1` VALUES (select * from temp)";
$qry4 ="INSERT INTO `temp1` VALUES ( '$ro','$un','$e m','$fn','$ln') ";
$res4=mysql_que ry($qry4)or die ("Error in query: $qry4. ".mysql_error() );
echo "<br>". $qry4;
$err=2;
}
header('locatio n:test.php?ord= $orderby&sor=$s ortby&tab=$ro') ;
}
//$smarty->assign('user', $rearr);
elseif(isset($_ GET['ord'])!=''||($_GET['sor'])!=''||($_GET['tab'])!=''||($_GET['act'])!=''||($_GET['act21'])!=''||($_GET['act22'])!=''||($_GET['page'])!=''||($_GET['act23'])!=''||($_GET['act24'])!='')
//elseif(isset($_ GET['ord'])!=''||($_GET['sor'])!=''||($_GET['tab'])!=''||($_GET['page'])!='')
{
echo $t=$_GET['tab'];
$qry .=" select * from temp1 type=heap";
$res1 = mysql_query($qr y);
echo $totalrow=mysql _num_rows($res1 );

/*paging code*/

/** how many rows to show per page **/
$rowsPerPage = 5;

/** by default we show first page **/
$pageNum = 1;

if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
/** counting the offset **/
$offset = ($pageNum - 1) * $rowsPerPage;

/********* Paging code starts Here ***********/

$totalCount = $totalrow;

/** how many pages we have when using paging? **/

$maxPage = ceil($totalCoun t/$rowsPerPage);

/** print the link to access each page **/

$self = $_SERVER['PHP_SELF'];
$nav = '';

if(!isset($_GET['page']))
{
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum) $nav .= "<font color='red'><b> $page</b></font>&nbsp;"; // no need to create a link to current page
else if($page<=10) $nav .= "<a href=\"$self?pa ge=$page\">$pag e</a> ";
}
}
else
{
if($pageNum-5 >= 1)
$start=$pageNum-5;
else
$start=1;

if($pageNum+5 <=$maxPage)
$end=$pageNum+5 ;
else
$end=$maxPage;

if($start==1)
$end=10;

if($end==$maxPa ge)
{
if($maxPage>9)
$start=$maxPage-9;
else
$start =1;
}

for($page=$star t; $page <=$maxPage && $page <= $end ; $page++)
{
if ($page == $pageNum)
$nav .= " <font color='red'><b> $page</b></font>&nbsp;"; /** no need to create a link to current page **/
elseif($pageNum >=1 and $pageNum<=$end)
$nav .= "<a href=\"$self?pa ge=$page\">$pag e</a> ";
}
}

if ($pageNum >1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?pa ge=$page\">[Previous]</a>&nbsp;";
$first = " <a href=\"$self?pa ge=1\">[First]</a>";
}
else
{
$prev = '&nbsp;'; /** we're on page one, don't print previous link **/
$first = '&nbsp;'; /** nor the first page link **/
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?pa ge=$page\">[Next]</a> ";
$last = " <a href=\"$self?pa ge=$maxPage\">[Last]</a> ";
}
else
{
$next = '&nbsp;'; /** we're on the last page, don't print next link **/
$last = '&nbsp;'; /** nor the last page link **/
}

echo $first . $prev . $nav . $next . $last ;
$id = "desc";
if(isset($_GET['act'])!='')
{
if($_GET['act']=='asc')
$id = "desc";
elseif($_GET['act']=='desc')
$id = "asc";
else
$id='asc';
$qry .=" order by uid $id";
}
$sort = "desc";
if(isset($_GET['act21'])!='')
{
if($_GET['act21']=='asc')
$sort = "desc";
elseif($_GET['act21']=='desc')
$sort = "asc";
else
$sort='asc';
$qry .=" order by user_name $sort";
}
$email = "desc";
if(isset($_GET['act22'])!='')
{
if($_GET['act22']=='asc')
$email = "desc";
elseif($_GET['act22']=='desc')
$email = "asc";
else
$email='asc';
$qry .=" order by email $email";
}
$fname = "desc";
if(isset($_GET['act23'])!='')
{
if($_GET['act23']=='asc')
$fname = "desc";
elseif($_GET['act23']=='desc')
$fname = "asc";
else
$fname='asc';
$qry .=" order by fname $fname";
}
$lname = "desc";
if(isset($_GET['act24'])!='')
{
if($_GET['act24']=='asc')
$lname = "desc";
elseif($_GET['act24']=='desc')
$lname = "asc";
else
$lname='asc';
$qry .=" order by fname $lname";
}

$qry .=" LIMIT $offset, $rowsPerPage";
echo $qry;
$res = mysql_query($qr y);
echo "<TABLE BORDER='1'>";
echo "<TR>";
echo "<TH><a href='test.php? act=$id'>uid</a></TH><TH><a href='test.php? act21=$sort'>un ame</a></TH><TH><a href='test.php? act22=$email'>e mail</a></TH><TH><a href='test.php? act23=$fname'>f name</a></TH><TH><a href='test.php? act24=$lname'>l name</a></TH>";
echo "</TR>";

while ($row3 = mysql_fetch_arr ay($res))
{
echo "<TR>";
echo "<TD>", $row3['uid'], "</TD><TD>", $row3['user_name'],"</TD><TD>",$row3['email'],"</TD><TD>", $row3['fname'],"</TD><TD>", $row3['lname'],"</TD>";
echo "</TR>";
}

echo "</TABLE>"; }

?>
Above program i executed i got warning error.as below




Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \testing\test.p hp on line 53
select * from temp1 type=ISAM order by uid asc LIMIT 0, 5
Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \testing\test.p hp on line 211
Apr 18 '07 #1
1 3329
code green
1,726 Recognized Expert Top Contributor
This query failed
Expand|Select|Wrap|Line Numbers
  1. select * from temp1 type=heap
. Probably because the table is empty
Apr 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2203
by: Joshua Beall | last post by:
Hi All, I am working on a registration system, and one of the things I am going to need to be able to do it setup the database tables for each event that I have registration for. Normally I would do this by hand, but I am wondering if there are any code libraries out there that could generate the SQL for me. Basically I would have a list of column names and types. I know I could just foreach() through the list, with a switch to...
0
8418
by: Didier ROS | last post by:
Hi, I am a newbie I want to create a temporary table and I get the following error message : mysql> CREATE TEMPORARY TABLE tempemp AS SELECT * FROM emp; ERROR 1044: Access denied for user: '@localhost' to database 'test1' Any help would be appreciated
0
4343
by: Partap Davis | last post by:
I asked this a couple days ago, but never got an answer, so I'll try to include some more detail: MySQL 4.0.12 on linux 2.4.18... I'm doing a join on 2 tables and trying to optimize it but I always end up with "Using temporary; Using filesort" and the query takes way too long... What can I do to speed this up?
0
2122
by: Peter Gorelczenko | last post by:
Good Morning, I'm running Alpha 4.1 on Linux. I'm new to MySql but familliar with othe= r=20 databases. I set up a user with "Create Temporary Tables" permissions. = That=20 user can create temp tables but can not alter or update the table. That= =20 user is getting "Update command denied to user..." for the temp table. = They=20 also get this error when an alter table is executed. Doesn't the user ha=
0
2205
by: Peter Gorelczenko | last post by:
I'm running as normal user (not root or database owner). This user has c= reate=20 temporary table priv. show tables partial: GRANT CREATE TEMPORARY TABLES ON `foobar0`.* TO 'foo'@'localhost' -> (foo= bar0=20 and foo are masks for the database name and user, respectively) I created two tmp tables with intermdiate results. I then try to join th=
0
2089
by: Soefara | last post by:
Dear Sirs, I have been developing an application on Windows with MySQL 3.23, making use of temporary tables. Now when I try to port the application to a Unix box running also MySQL 3.23, I keep running into "access denied" errors with the queries which employ temporary tables. This only happens with CREATE TEMPORARY TABLE type queries, all other queries work fine.
4
2097
by: steve | last post by:
I like to create some temprary tables (in-memory tables) when mysql starts up. How do I do that. Thanks. -- Posted using the http://www.dbforumz.com interface, at author's request Articles individually checked for conformance to usenet standards Topic URL: http://www.dbforumz.com/mySQL-set-temporary-tables-startup-ftopict224284.html Visit Topic URL to contact author (reg. req'd). Report abuse:...
11
16300
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the equivalent to the SQL 'with' using TSQL? If there is not one, what is the TSQL solution to creating a temporary table that is associated with an SQL statement? Examples would be appreciated. Thank you!!
1
26992
by: Stefan van Roosmalen | last post by:
Hi there, Is there a way to list the TEMPORATY tables? I have tried SHOW TABLES, but this command only list the regular tables. Thank you very much for your answer. Regards, Stefan.
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.