This topic is locked

Copy record to another table

3/7/2012 4:48:07 PM
PHPRunner General questions
H
hernanccs author

Is it possible to add a button on the list page, next to each record, that copy that record to another table?
i tried to do something similar to the script included on the shop cart template (the add to cart thing), but it didnt work <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=19163&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />
I have searched the forums already with no luck, im sure someone else made this question before but couldnt find anything.
Thanks and regards

H
hernanccs author 3/8/2012



Check this thread: http://www.asprunner.com/forums/topic/17578-email-button-for-earch-record/


Any way to do this using the Insert Button tool on the edit page?
i tried adding one and placing this on the server tab of the button properties but nothing happens when i click the button on the browser
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "insert into TableName (Field1, Field2)

values (Value1, Value2)";

db_exec($strSQLInsert,$conn);
also tried the instructions i found on the help file but no luck either
global $dal;

if ($keys["ProductID"])

{

//add new records to the ShoppingCart table

//save current username in the UserID field

$ShoppingCart = $dal->Table("ShoppingCart");

$ShoppingCart->Product = $keys["ProductID"];

$ShoppingCart->Quantity = 1;

$ShoppingCart->UserID = $_SESSION["UserID"];

$ShoppingCart->Add();

}

$result["txt"] = "Product was added";
of course i replaced the table name and fields names with my actual table/field names

C
cgphp 3/8/2012
H
hernanccs author 3/8/2012

I have searched and read the forums for hours, maybe 4 or 5 with no luck; every suggestion i have read heads to email related solutions, even if the questions has nothing to do with emails; guess most of those users found the solution somewhere else or just gave up on trying to solve the issue.
Im trying to do something really simple here; think about the shopping cart template.
There is a inventory_list view where there is a button name "Add to Cart"; when you click that button a record is created on the shopping_cart table. (it makes some extra tasks i dont need here, like verifying if the product is in the cart already or not, and calculate price and total base on quantities)
All i need to do is; on TableA_list add a button, similar to the "Add to cart", that just create a copy of FieldA and FieldB on TableA to FieldA and FieldB on TableB; it really doesnt matter if a record already exists with same value
i found out on the shopping cart template i could achieve this adding {$Add_to_Cart} on the list view
then on the list page after record processesd event adding
$mess="";

$mess="<A class=tablelinks href=\"TableA_list.php?item=" . $data["FieldA"] . "\"><STRONG>Add to Cart</STRONG></A>";

$record["Add_to_Cart"]=$mess;
and the last part, which is the part that is not working add a script to the list page before display event

problem here is the cart template contains like 120 lines of code i dont think i need
any suggestion?
thanks

C
cgphp 3/8/2012

The email code is not a problem. You have to replace it with the insert/update sql statement. Follow the above link for inspiration.

H
hernanccs author 3/8/2012



The email code is not a problem. You have to replace it with the insert/update sql statement. Follow the above link for inspiration.


Thanks for your reply but that is not helping me <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=64817&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
i tried this on the view page before display event, it does the job with with some issues
global $conn;

$strSQLInsert = "insert into TABLEA (FieldA, FieldB, userid) values ('".$values["FieldA"]."','".$values["FieldB"]."','".$_SESSION["UserID"]."')";

db_exec($strSQLInsert,$conn);
problems with this solution

-i have to click back to list everytime i want to copy a record; if i use a header to go back automatically to the list page, the last searched that was done is lost and we are back at the initial view with all records.

-i lose view functionality, it copy the record everytime i click view.

-cant find a way to change the on mouse over icon message (it always displays view)

C
cgphp 3/8/2012

It's hard to help you without seeing your actual code. If you follow the instructions in the link above you can solve your issues.

H
hernanccs author 3/8/2012



It's hard to help you without seeing your actual code. If you follow the instructions in the link above you can solve your issues.


OK, i added the alias on the query and set the custom view to create the button, but how do i run something like this from a java script to make it copy/write the values to TableB?
global $conn;

$strSQLInsert = "insert into TABLEA (FieldA, FieldB, userid) values ('".$values["FieldA"]."','".$values["FieldB"]."','".$_SESSION["UserID"]."')";

db_exec($strSQLInsert,$conn);
thanks for your time, really appreciate

H
hernanccs author 3/10/2012

Any way to do this using a hyperlink instead of a button?

Sergey Kornilov admin 3/10/2012

Probably the best way is to make this button look like a regular hyperlink.
Here is how a typical button looks:

<SPAN class=runner-btnframe><SPAN class=runner-btnleft></SPAN><SPAN class=runner-btnright></SPAN><A id=New_Button class=runner-button href="#" typeid="ib">New_Button</A></SPAN>


If you remove all spans that will look like a regular hyperlink:

<A id=New_Button class=runner-button href="#" typeid="ib">New_Button</A>
H
hernanccs author 3/10/2012



Probably the best way is to make this button look like a regular hyperlink.
Here is how a typical button looks:

<SPAN class=runner-btnframe><SPAN class=runner-btnleft></SPAN><SPAN class=runner-btnright></SPAN><A id=New_Button class=runner-button href="#" typeid="ib">New_Button</A></SPAN>


If you remove all spans that will look like a regular hyperlink:

<A id=New_Button class=runner-button href="#" typeid="ib">New_Button</A>



hmm, what about the code to copy the record to the second table?

i was able to do it by clicking the view button adding this code to the before display event, but i would like to run it by clicking that link
global $conn;

$strSQLInsert = "insert into TABLEA (FieldA, FieldB, userid) values ('".$values["FieldA"]."','".$values["FieldB"]."','".$_SESSION["UserID"]."')";

db_exec($strSQLInsert,$conn);
any idea?
thanks Sergey