![]() |
Allow users to delete an adoptable
I'm attempting to make a feature where users can release a pet to the wild, which basically just means permanently deleting it.
I've just copied and modified my pets' bio functions in their myadopts.php and myadoptsview.php to look like below. In class_ownedadoptables.php, I just have a blank public function "doReleasePet()" because I'm honestly just scared to try experimenting with deleting things. :P Afraid I'll end up deleting a whole database table or something lol. Can someone help me out? ;-; Am I going in the right direction at least? myadopts.php PHP Code:
PHP Code:
PHP Code:
|
I think this'll work...?
PHP Code:
|
Getting errors. I tried adding this to the doReleasePet in the class_ownedadoptable.php and got a fatal error.
Code:
Fatal error: Call to a member function delete() on null in /home/mysgardia/public_html/classes/class_ownedadoptable.php on line 103 Code:
Database error 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lavie'' at line 1 Code:
$mysidia->db->delete("owned_adoptables", "aid='{$this->aid}'"); |
Check that there's not an extra quotation mark at the end? That it ends with:
'{$this->owner}'"); not '{$this->owner}''"); There was maybe a 30 second window in which the typo existed and I'll be surprised if you managed to grab it then. |
Yea, I made sure everything looked right after adding it. Gives me this error on the myadopts.php page:
Code:
Database error 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' AND owner =''' at line 1 PHP Code:
|
Oh, woops! You do need it after {$this->aid}, good job catching that!
PHP Code:
PHP Code:
However, the problem is where you're putting it. It can't find the data you're telling it to find because you can't call $this->aid inside myadopts.php, because that file does not have a variable set at the top called $aid. You'd have to use $this->adopt->getAdoptID() instead (this file has a variable called $adopt which is a reference to the class_ownedadoptables.php where getAdoptID() exists, possibly even $this->adopt->aid would work with the proper permissions). I was thinking you'd put this inside doReleasePet(), since you were calling with $this->adopt->doReleasePet(); but left it empty inside class_ownedadoptables.php? I used aid='{$this->aid}' assuming it'd be there (because $aid exists in the context of this file) if you don't want to do that, then I suggest just inside myadopts.php: PHP Code:
|
Ahh perfect!
When I tried putting mysidia->db->query part in class_ownedadopts it still gave me an error, so I just used the second bit you gave me instead and it worked! I don't think I'll need to use this anywhere else so I'll just keep it in myadopts.php file for now. Thank you so so much Kyttias! <3 |
Okay, new question.
I wanted this primarily so that users could delete unwanted offspring their creatures happen to breed. I would also need the offspring's ID to be deleted (more like updated to NULL) from their parents' descendants column in owned_adopts. Is this possible? :c Otherwise by just deleting the offspring's data, the parents' profile pages bring up an error since the child no longer exists. Also vice versa if a parent was deleted, its ID would need to be updated to NULL in the child's mother/father columns. I'm using pretty much the exact coding that you and Abronsyth discussed in the Lineage thread. EDIT: Would this work, or something like this? PHP Code:
PHP Code:
PHP Code:
|
No, partially because editting the adopts_pounds table won't help you, lol?
The babies are stored as an psuedo-array with the parents. You have to take the adopt, identify its parents, extract the arrays from the database for each parent, explode these arrays from a strings into an an actual arrays PHP can work with, carefully remove the id of the pet you're deleting, implode it back into a string, and reinsert it into the database. Confirmed working (edit: Updated Mar 9 @ 2:21AM EST!): PHP Code:
|
Oh whoops lol! I kinda just copied that from something else and forgot to change the table.
But aw crud. :/ Hmm, I guess that foils my plans until a later date haha. Do you think there would be a way to instead check if the adopt exists before displaying it as a parent and/or offspring on the levelup.php files? Or would that be just as tedious? |
All times are GMT -5. The time now is 05:13 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.