Database functions?

Forum
Last Post
Threads / Messages

Infernette

CODE CODE CODE CODE CODE
Member
Joined
Jan 29, 2013
Messages
164
Points
0
Location
Where I live? I live home.
Mysidian Dollar
15,625
I see that there are normal ways of going about deleting certain rows in the database (I.E. All adopts with the owner "None") And there are ways to count rows (I.E. Counting all adopts that you own that are under level 5 so you can limit eggs when adopting) but they seem to be hard to incorporate with the normal way that the database functions are handled. Is there any way to go about this in the same way but with the whole "$mysidia->db-> stuff?



(Currently working on a random adopt maker, it's getting fun (even though a simple show description of the adopt it's showing is getting annoying XD))
 
Well its easy to delete certain rows, the below code gets rid of every entry that has owner as 'none' in table prefix_owned_adoptables.

PHP:
$mysidia->db->delete("owned_adoptables", "owner = 'none'");

Its also super easy to get the number of rows, simply do:

PHP:
$count = $mysidia->db->select("tablename", array(), "conditions")->rowCount();
 
Okay I got everything else to work but now the page isn't recognizing the adopt like the other pages I made. This is going to be hard >.<

Here's all the code in case it matters (duplicated/modified the daycare page)
  Spoiler: code 
Code:
<?php

class CrecheController extends AppController{

    const PARAM = "aid";
    const PARAM2 = "confirm";
    private $view;
	private $subController;
	private $adopt;
	private $image;

    public function __construct(){
        parent::__construct();
		$mysidia = Registry::get("mysidia");
		if($mysidia->input->action() == "click" or $mysidia->input->action() == "siggy") $this->adopt = new OwnedAdoptable($mysidia->input->get("aid"));
		if($mysidia->user instanceof Member){
		    $status = $mysidia->user->getstatus();   
			if($status->canlevel == "no") throw new InvalidActionException($mysidia->lang->banned);
		}	
    }
	
	public function view(){
		$mysidia = Registry::get("mysidia");
		$document = $mysidia->frame->getDocument();
        $document->setTitle($mysidia->lang->daycare_title);
        $document->addLangvar($mysidia->lang->daycare, TRUE);

		try{
		    $daycare = new Daycare;
			$adopts = $daycare->getForadopts();
		}
		catch(DaycareException $dae){
		    $message = $dae->getmessage();
		    $document->addLangvar($mysidia->lang->{$message});
			return;
		}
		
		$daycareTable = new Table("daycare", "", FALSE);
		$daycareTable->setBordered(FALSE);
		$total = $daycare->getTotalAdopts();
        $index = 0;

		for($row = 0; $row < $daycare->getTotalRows(); $row++){
	        $daycareRow = new TRow("row{$row}");
            for($column = 0; $column < $daycare->getTotalColumns(); $column++){
			    $adopt = new OwnedAdoptable($adopts[$index]);
				$image = new Link("creche/adopt/{$adopt->getAdoptID()}", $adopt->getImage("gui"), TRUE);
				      $level = $mysidia->db->select("levels", array("primaryimage", "alternateimage","description"), "adoptiename='{$this->adopt->lvltype}' AND thisislevel='{$adopt->currentlevel}'")->fetchObject(); 

				$stats = new Comment("{$level->description}");
				$daycareCell = new TCell(new ArrayObject(array($image, $stats)), "cell{$index}");
                $daycareCell->setAlign(new Align("center", "center"));
				$daycareRow->add($daycareCell);
				$index++;
				if($index == $total) break;
            }
            $daycareTable->add($daycareRow);			
		}
		
        $document->add($daycareTable);
		if($pagination = $daycare->getPagination()) $document->addLangvar($pagination->showPage());
	}
	public function creATEaBunchOFeggsens(){
		$mysidia = Registry::get("mysidia");
		$document = $mysidia->frame->getDocument();
		
$mysidia->db->delete("owned_adoptables", "owner = 'none'");  
			$document->setTitle("Delete Successful!");
			$document->addLangvar($message);
			$document->add(new Link("myadopts/manage/nothin", "Deleted"));
			return;
}
	public function alladoptsdeletedgoodbye3231281ye721(){
		$mysidia = Registry::get("mysidia");
		$document = $mysidia->frame->getDocument();
		
$mysidia->db->delete("owned_adoptables", "owner = 'none'");  
			$document->setTitle("Delete Successful!");
			$document->addLangvar($message);
			$document->add(new Link("myadopts/manage/nothin", "Deleted"));
			return;
}
	public function adopt(){
		$mysidia = Registry::get("mysidia");
		$document = $mysidia->frame->getDocument();
if($this->adopt->owner= "None"){
$n = count($mysidia->db->select("owned_adoptables", array("aid"), " owner='{$mysdia->user->username}' AND currentlevel < 6")->fetchAll()); 
				 $row = $mysidia->db->select("users", array(), constant("PREFIX")."users.username='{$mysidia->user->username}' ")->fetchObject();
				 			$document->setTitle("Adoption Successful!");
		 $slotsleft = $row->slots - $n;
		 if($slotsleft >= 1){
            $mysidia->db->update("owned_adoptables", array("owner" => $mysidia->user->username), "breedcode = '{$adopt->getAdoptID()}'");
			$document->setTitle("Adoption Successful!");
			$message = "<br>You have adopted this pet! You can now manage it in your ";
			$document->addLangvar($message);
			$document->add(new Link("myadopts/", "Holding Area."));
			}
elseif($slotsleft < 1){
			$document->setTitle("Error");
						$message = "<br>You have too many eggs to adopt this pet, you need to hatch one before getting another.";
			$document->addLangvar($message);
}
return;
}
else{
$document->setTitle("Cheating");
			$message = "<br>Not supported in the forest, please upgrade your account to BANNED.";
			$document->addLangvar($message);
}
}
}
?>
 
Last edited:
Well copying/pasting pages is kinda tricky for sure. First of all, the lang vars need to be modified properly. You need to create a lang file inside the folder /lang with the appropriate lang var defined in array format. On the other hand, keep an eye on the naming conventions/patterns for your class method names.
 
yeah I'm way past that step, I just can't seem to get the adopt function to work with $adopt->*whatever* which is kinda odd since it has worked with any of the other pages I've made.

I might try to get the adopt ID from the URL and work it to use that to get the info, but it seems to be a complicated process and none of the tutorials help with using slashes instead of the old mys way >.<


I guess while I mull over how to do that I should work on making companions and art for them, so no more questions for now XD

Thanks :)

EDIT: Holy carp I just realized I can just move the adopt function to a different page and it'll still work. HERPDERP. >.<
 
Last edited:
Arguing with it to make multiple types (Rand y u no listen :madnoes: ) but other than that I think I have everything to get this site done in 16 days XD

Except cron jobs. But looking into alternate ways is easy...
 
Last edited:
I see, looks like you are making some progress. Cron jobs can be a pain to work with, you can actually simulate cron jobs with PHP simply by having scheduled tasks run whenever a user visits the page, a member, guest or even bot wont really matter here. Make sure to check whether the cron jobs should run by comparing datetime string/integer, otherwise you may end up with multiple cron jobs executing at times they really should not.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,132
Members
1,603
Latest member
Monako
BETA

Latest Threads

Top