I've created a user directory (contact list) of users. I'm using the data displayer and have to add an "edit" link to each entry in the directory so that there's a way to edit the user's information. I can add an entry without any problem. However, I have custom code (see below) that runs after the DB Save to create the "edit" link and insert it into the database. I've tried everything I can think of but still can't get this custom code to do anything. I get no errors and my SQL syntax is correct. I'm completely stuck. Any ideas?
The echoed output ($emp_id and $query) and both look correct. I even copy/pasted the query into MySQL and ran it successfully. I must be missing something else. Also, I'm not sure what the best practices are for querying a DB in Chronoforms. If there's something that easier/better aside from a normal SQL query, please let me know. Thanks for your input.
<?php
$db =& JFactory::getDBO();
$emp_id = $db->insertid();
$query = "UPDATE pd_directory SET edit_link='<a href=\"index.php/component/chronoforms/?chronoform=directory_edit&token=" .$emp_id. "\">Edit</a>' WHERE employee_id='" .$emp_id. "'";
$db->setQuery($query);
echo $db->getErrorMsg();
echo "The ID is: " .$emp_id. "<br>";
echo "The query is: " .$query. "<br>";
?>
The echoed output ($emp_id and $query) and both look correct. I even copy/pasted the query into MySQL and ran it successfully. I must be missing something else. Also, I'm not sure what the best practices are for querying a DB in Chronoforms. If there's something that easier/better aside from a normal SQL query, please let me know. Thanks for your input.
Hi Justin,
The line $db->setQuery($query); sets the query but doesn't execute it. You need to add $db->query(); after it.
Can you not create this value before the DB Save and include it there? Or better, create it when it's needed rather than save it at all. You have employee_id in the table so that should be straightforward.
Bob
The line $db->setQuery($query); sets the query but doesn't execute it. You need to add $db->query(); after it.
Can you not create this value before the DB Save and include it there? Or better, create it when it's needed rather than save it at all. You have employee_id in the table so that should be straightforward.
Bob
Thank you for the response, Bob! That solved my update issue.
The reason I'm saving it in the database is because I'm currently using the Data Displayer (for easy sorting and pagination) and I don't think I can dynamically add an "edit" column to the output of the data displayer. Am I correct in this assumption?
I may change things up and create the table manually (so I can add alternating row colors) in which case I will create the "edit" link dynamically.
Thanks again for your assistance.
The reason I'm saving it in the database is because I'm currently using the Data Displayer (for easy sorting and pagination) and I don't think I can dynamically add an "edit" column to the output of the data displayer. Am I correct in this assumption?
I may change things up and create the table manually (so I can add alternating row colors) in which case I will create the "edit" link dynamically.
Thanks again for your assistance.
This topic is locked and no more replies can be posted.