Jump to content

Moving Table Rows To Different Tables.


MrCreeky

Recommended Posts

Hi,

 

I'm trying to come up with a solution to move multiple entries to a different table in one end user click.

 

For example, I have a table called "Service". Within that table I have a number of fields "id,row-1,row-2,row-3,row-4"

 

Within the service row-1 will have the same value for a number of entries that are displayed to the end user on one page showing a catalogue of information. The id will of course be unique.

 

I need to be abel to move all the rows from the service table that have the same value based in row-1.

 

At the moment I'm trying to filter this information based on a URL Permitter (?id=) I'm passing to the page however I have run in to some problems I don't understand.

 

Here is how I have been trying to filter the data and copy it over the "Archive" table.

 

 

$colname_move_rs = "-1";
if (isset($_GET['id'])) {
 $colname_move_rs = $_GET['id'];
}
mysql_select_db($database_encomSQL, $encomSQL);
$query_move_rs = sprintf("INSERT INTO archive (row-1,row-2,row-3,row-4)  SELECT row-1,row-2,row-3,row-4 FROM service WHERE row-1 = %s", GetSQLValueString($colname_move_rs, "int"));
$move_rs = mysql_query($query_move_rs, $encomSQL) or die(mysql_error());
$row_move_rs = mysql_fetch_assoc($move_rs);
$totalRows_move_rs = mysql_num_rows($move_rs);

 

The type of errors I'm getting are as follows:

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in move.php on line 41

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in move.php on line 42

Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in move.php on line 44

 

If anyone could offer me some help, I would be most grateful!

Link to comment
Share on other sites

Hyphenated column names are no good. Use backticks ` to clear the issue.

 

$query_move_rs = sprintf("INSERT INTO archive (`row-1`,`row-2`,`row-3`,`row-4`) SELECT `row-1`,`row-2`,`row-3`,`row-4` FROM service WHERE `row-1` = %s", GetSQLValueString($colname_move_rs, "int"));

 

EDIT: I noticed that your code is dependent on $_GET['id'] existing. However, this block of code isn't helping the cause:

 

$colname_move_rs = "-1";
if (isset($_GET['id'])) {
 $colname_move_rs = $_GET['id'];
}

 

If $_GET['id'] isn't set, $colname_move_rs is equal to -1. Now, I'm not sure that that is OK in your books, but I wouldn't think so. Your query should not fire unless an appropriate value for $_GET['id'] is found. Not only checking if it isset, but checking whether a value even exists and whether that value is numeric or not. If $_GET['id'] == 'string', that is no good for your query.

 

So, check value exists and check what that value is (numeric or string). Then, if it checks out, execute your query.

Edited by mrMarcus
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.