Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] create and fetch data from temporary table


[SOLVED] create and fetch data from temporary table

Reply
  #1 (permalink)  
Old 06-12-08, 08:45 AM
zodehala zodehala is offline
Wannabe Coder
 
Join Date: Mar 2007
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] create and fetch data from temporary table

PHP Code:

<?php    

$link 
mysql_connect("localhost","root","123");
$db =  mysql_select_db("db",$link);

$temp_table_create "
                CREATE TEMPORARY TABLE  IF NOT EXISTS  `temp_del_log` (
                  `removerid` int(10) unsigned NOT NULL default '0' COMMENT 'konuyu silenin id',
                  `removername` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'konuyu silenin ismi',
                  `deletedid` int(10) unsigned NOT NULL default '0' COMMENT 'konusu silinenin id',
                  `deletedname` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'konusu silinenin ismi',
                  `type` enum('post','thread') collate utf8_unicode_ci NOT NULL default 'thread' COMMENT 'tür',
                  `prefix` varchar(250) collate utf8_unicode_ci NOT NULL COMMENT 'silinen konu ismi',
                  `title` varchar(250) collate utf8_unicode_ci NOT NULL COMMENT 'silinen konu başlığı',
                  `reason` varchar(125) collate utf8_unicode_ci NOT NULL COMMENT 'silinme sebebi',
                  `dateline` int(10) unsigned NOT NULL default '0' COMMENT 'silinme tarihi',
                  KEY `type` (`type`,`dateline`)
                ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci  ;
            "
;
$temp_table_insert 
    
"INSERT INTO temp_del_log (removerid, removername, deletedid, deletedname, type, prefix, title, reason, dateline)
    VALUE('5', 'zodehala', '20', 'tom', 'thread', 'thread', 'delete', 'not important', '"
.time()."')";
            
mysql_query($temp_table_create)or die (mysql_errno()."<br/>".mysql_error());        
mysql_query($temp_table_insert)or die (mysql_errno()."<br/>".mysql_error());

?>

<a href="x.php?delete=thread" tabindex="1" accesskey="1" target="_self">Click</a

<?php            
switch ($_GET["delete"]){
        
//konu silmek için...
        
case  "thread"    :
        
            
$infox mysql_fetch_array(mysql_query("SELECT * FROM temp_del_log"));
                echo 
$infox["deletedname"];                
        break;        
    }
?>

when i cliked to link why can i not fetch data from table ? where is my error ?
Reply With Quote
  #2 (permalink)  
Old 06-12-08, 09:44 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
The posted code works for me, echoing "tom" after the link is clicked.

Note: The <a... link is missing a closing > at the end of that line of HTML.

Is x.php the name of the file that code is in? You can just use the following if you want the link to refer to the same file -

PHP Code:

<a href="?delete=thread" tabindex="1" accesskey="1" target="_self">Click</a
Logically the code is doing some unnecessary things. The queries to create and insert the data into the temporary table are executed each time the page is fetched. So, when the page is first visited, the temporary table is created and the row inserted, but this is not used and the temporary table is deleted when the script ends (when the connection to the database server is closed.) Then when you click on the link and the page is requested again, the temporary table is created again and the row inserted again. This logic should be changed so that the temporary table is only created/inserted when the switch/case statement matches a value where you want to use the temporary table.

The code also does not have any error checking on the mysql_query() in the switch/case statement, so if that query should fail, the code won't output what you expect.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 06-12-08, 09:52 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
If you are getting no echoed output in FF, it is because of the missing > on the end of the link. The HTML is broken and the "tom" output is present in the "view source" but is not rendered by the browser.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #4 (permalink)  
Old 06-12-08, 10:16 AM
zodehala zodehala is offline
Wannabe Coder
 
Join Date: Mar 2007
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
oooohhhhhhhhh very very thanx
Reply With Quote
  #5 (permalink)  
Old 06-12-08, 10:24 AM
zodehala zodehala is offline
Wannabe Coder
 
Join Date: Mar 2007
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mab View Post
Logically the code is doing some unnecessary things. The queries to create and insert the data into the temporary table are executed each time the page is fetched. So, when the page is first visited, the temporary table is created and the row inserted, but this is not used and the temporary table is deleted when the script ends (when the connection to the database server is closed.)
i already want like this
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.