![]() |
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? |
I updated the code above, give it a shot?
I can also try to make an addendum to the family tree code to prevent nonexistent pets from displaying. That'll definitely be easier in the long run, I think. (Actually no, it wasn't, I learned something from HoF in the process.) Basically, in the family tree code, we need to wrap the offspring in a try/catch statement, so find the foreach loop: PHP Code:
|
Thank you so much Kyttias! I'm going to test it out later when I get home (:
|
I'm now using code from both post #9 and post #11 just to be safe. While I was discussing this with HoF he expressed some of the same concerns I had, however, so it's worth bringing up:
We don't really know if other side effects will exist. I can't immediately fathom any, but that doesn't mean they don't exist. What if a pet is deleted half way through a trade? Will it corrupt the trade section for one person, both people, everyone? And, is it possible to to keep the pet's profile open, release it to the pound, and because you still have your pet's page open as if you own it - delete it? Would that break the pound? I haven't fully considered these things so please do some testing. It's hard to officially approve of deleting pets when we don't know what could happen. :catfish: |
Hmm, alright. I think I'll try getting a tester site up and do testing before releasing this on my site then. Those are some valid points made and could definitely turn into an issue if anyone were to abuse it.
EDIT: Alternatively, perhaps I can instead just make a page just like the pound and allow users to "release" their pets there, clearing any family data, and every few days the pets can be automatically (or manually) deleted thereafter. Pets on this page wouldn't be allowed for readoption. |
Alright so coming back to this. :P The code that ignores the error when an offspring doesn't exist is working great. Is there a way to have this also work if mothers and fathers were deleted as well? Whenever a mother or father is deleted, the babies get an error on their pages saying so. I tried to look in the code and figure it out myself but not getting anywhere. ><
|
I'll work on this when I get back from... work. *sigh*
edit: See later post for solution. |
Ahh Kyttias thank you! <3 It's no rush. I just happened to fiddle with it more and noticed that problem unfortunately.
I'm not using grandparents on my site at the moment so it wouldn't be a problem for me luckily, though others following this might find that useful. Not sure if I ever will display grandparents, so I'm mainly just focused on ignoring the error for parents as well. I also still need to do some testing to make sure there aren't any major errors with adding the deleting part. Plan on getting to that soon! |
The best thing to do will be just to make a try/catch as we did before, actually, with the children. Telling you where to make edits is a little harder, so, from the thread where the family tree was made, post number four, the first bit of code. That. Where-ever you put that, no matter how you designed it within, it'll be easiest just to put this above it, so we have both:
PHP Code:
So why do we need this code first? Basically, the code from the post I referred to is checking whether or not the current adoptable has a parent held in its database column (it's checking for NULL, so, so long as something there, it should try to render something). Well, we're backing up a step. First we're checking if the field is not NULL - okay, something is there? Okay, but does that pet actually exist? We check that. And if doesn't exist? We inform the code it is NULL, therefore stopping the original code. If something about this goes strangely, go ahead and send me the file via PM. :meow: |
You really are the best! <3 It works, at least for mothers and fathers. Someone else would need to test grandparents. :P Thank yoouuu!
|
Still haven't tested if deleting adopts causes any errors, but did wanna say I instead just basically duplicated the pound and made it into the "Wild". Players can't adopt these pets but they can view them and their profiles. So far it seems to be working okay and I may just stick to this. I need to trim and clean up a lot of the code though.
Also working on getting pets to display randomly and limited to only maybe 50 or so at a time. Would be horrible to visit a page with 500+ pets there. :P I'm also not sure if I wanna delete pets manually every so often (for tidyness), or just keep them there. Probably just gonna get my users to vote on this. http://i.imgur.com/UWtIdwF.png |
I've run into a problem I can't figure out. I've copied all the pound stuff and renamed it release and I have everything working, except when it gets to the "confirm" page, it's blank. Is there a actual file that I've neglected or just a piece of code that I've failed to change? It just shows a blank page.
To better explain, it displays the link to "release" the pet, it shows the page asking if they're sure they want to "release" or "keep" the pet, but on the final step it shows a blank page, instead of showing "You have successfully released your pet!" If you could tell me what files you need to look at to help me, I'd be happy to paste them here. |
Anyone, please?
|
All times are GMT -5. The time now is 10:28 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.