Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2015, 03:40 AM
MikiHeart's Avatar
MikiHeart MikiHeart is offline
Premium Member
 
Join Date: Apr 2009
Posts: 187
Gender: Female
Credits: 20,326
MikiHeart
Default Seeking basic run down of php and database

I'm trying to my hardest to change my way of coding to suit the site, but the one thing I can't seem to get a grasp of, is how all the database queries are handled.

Can someone please give me a basic run down, since we don't have any documentation(As far as I know).

$mysidia->db->select("table", array(), "thing = '$thing'")->fetchColumn();

I can assume that this part "$mysidia->db->select" is used to select the database information and so on. Instead of like "mysqli_query()", which is what I'm use to.

I don't understand why the array is there, and the "->fetchColumn()" part. I also don't understand why there is like "$result" variable after the MySql codes.

So I just need a basic run down, a little bit of help to understand, then I can start coding and working on features.

(I'm working on a few things. Like displaying a user's favourite pet in the sidebar)

Please and thank yous D=!!!
Reply With Quote
  #2  
Old 01-13-2015, 06:15 AM
MikiHeart's Avatar
MikiHeart MikiHeart is offline
Premium Member
 
Join Date: Apr 2009
Posts: 187
Gender: Female
Credits: 20,326
MikiHeart
Default

Okay. So I think I've got it. After fiddling and being impatient for a reply.

But I would like a second pair of eyes to look at my code. (Instead of adding the php in the module area, I prefer to add it to the class_sidebar.php file. It's easier for coding and checking backwards and forwards.

The main code:

Code:
protected function setFavPetSB(){
$mysidia = Registry::get("mysidia");

$userfavpet = $mysidia->db->select("users_profile", array("favpet"), "username = '{$mysidia->user->username}'")->fetchColumn(); 
if ($this->userfavpet == "0"){
$this->FavPetSB = new Paragraph; 
$this->FavPetSB->add(new Comment("<b>No Favorite Pet Set</b>"));
}
else{
$this->FavPetSB = new Paragraph; 
$this->FavPetSB->add(new Comment("<b>Favorite Pet!</b>"));
$this->FavPetSB->add(new Link("levelup/click/{$userfavpet}", new Image("levelup/siggy/{$userfavpet}"), TRUE));
}

$this->setDivision($this->FavPetSB);           

}
Reply With Quote
  #3  
Old 01-13-2015, 09:34 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,947
Kyttias is on a distinguished road
Default

If you like, I've been slowly working on this guide.

Or, in short, for just your question:

Database SQL Statements
You’ll need to have access to the registry first, in whatever function you're dealing with, of course.
PHP Code:
$mysidia Registry::get("mysidia"); 
Counting Rows
Count how many rows match a specific query:
PHP Code:
$mysidia->db->select("Table", array("Column"), "Row='{$somevalue}' and Row >= {$somevalue}")->rowCount(); 
Compare to:
Code:
SELECT COUNT(Row) FROM Column WHERE Row='$somevalue' and Row >= {$somevalue};
Where Data
Fetching an exact value in a specified column:
PHP Code:
$mysidia->db->select("Table", array("Column"), "Row = '$somevalue'")->fetchColumn(); 
Compare to:
Code:
SELECT Column FROM Table WHERE Row='$somevalue';
Fetching Row Data as an Object
Example:
PHP Code:
$pet $mysidia->db->select("owned_adoptables", array(), "owner='{$mysidia->user->username}' ORDER BY RAND() LIMIT 1")->fetchObject(); 
You could now use {$pet->name} and {$pet->currentlevel}, etc. (This example chooses a random pet owned by the user.)
Creating a New Row of Data
Example:
PHP Code:
$mysidia->db->insert("Table", array("Column" => $somevalue"Column" => 'somevalue')); 
Compare to:
Code:
INSERT INTO table_name (Column1, Column2, Column3) VALUES ($somevalue1, $somevalue2, $somevalue3);
Updating Data
PHP Code:
$mysidia->db->update("Table", array("Column" => '$somevalue'), "Row = '$somevalue'"); 
Compare to:
Code:
UPDATE Table SET Column='$somevalue' WHERE Row='$somevalue';
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #4  
Old 01-13-2015, 09:57 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,947
Kyttias is on a distinguished road
Default

As for your code above, because the Sidebar widget is partially controlled on the AdminCP you will also have to make changes there. AdminCP > Module > Create New Module:


You could also probably manually do this in the database (in the _modules table), but it's just not being done with code alone. (Note: the Module Order slot controls the order in which the modules in the sidebar will appear, lower numbers are higher.)

I also notice your code above is only a setter but there is no getter. The money bar has a getter, so just add one similar above your code:
PHP Code:
public function getFavPetSB(){
        return 
$this->FavPetSB;
    } 
I also propose the following changes in your code:

PHP Code:
protected function setFavPetSB(){
        
$mysidia Registry::get("mysidia");

        
$userfavpet $mysidia->db->select("users_profile", array("favpet"), "username = '{$mysidia->user->username}'")->fetchColumn(); 
        if (
$this->userfavpet == "0"){
            
$this->FavPetSB = new Paragraph
            
$this->FavPetSB->add(new Comment("<b>No Favorite Pet Set</b>"));
        }
        else{
            
$adopt = new OwnedAdoptable($userfavpet);
            
$this->FavPetSB = new Paragraph
            
$this->FavPetSB->add(new Comment("<b>Favorite Pet!</b> <br/>
                <a href='/myadopts/manage/
{$userfavpet}'><img src='{$adopt->getImage()}'></a>
                "
));
        }

        
$this->setDivision($this->FavPetSB);
    } 
Using "$adopt = new OwnedAdoptable($userfavpet);" you can also pull up data like {$adopt->getName()} and {$adopt->getCurrentLevel()}.

Lastly, the code you had looked familiar, but it's something that's slightly broken in the code itself, currently. Inside class_userprofile.php I'd replace the getFavpet function:

PHP Code:
 public function getFavpet(){ 
      if(
is_numeric($this->favpet)){ 
          
$adopt = new OwnedAdoptable($this->favpet); 
          
$favimg $adopt->getImage(); 
          
$this->favpet = ($this->favpet == 0)?new Comment("None Selected"):new Link("levelup/click/{$this->favpet}", new Image($favimg), TRUE);  
      }  
      return 
$this->favpet;       
  } 
Because unfortunately, levelup/siggy/{$numberhere} is not an image, not even if you add a file extension to it.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 01-13-2015 at 10:12 AM.
Reply With Quote
  #5  
Old 01-14-2015, 05:01 AM
MikiHeart's Avatar
MikiHeart MikiHeart is offline
Premium Member
 
Join Date: Apr 2009
Posts: 187
Gender: Female
Credits: 20,326
MikiHeart
Default

Thank you so much for the basic run down and the guide.

As for the code, thank you for the edits :) I already have the getter, and the module set up.

The code works, I'm just rusty and needed a second pair of eyes to make sure.

I know that levelup/siggy/{$numberhere} isn't an image, yet it still works, oddly enough. But you're right, it should be changed.

Thank you again for the help. I can finally start working on editing the current features and adding my own.

(I plan to add my own item rarity system, but also add a rarity system for pets. Because I want them to be random in what they adopt. Since our site is focused on collecting)
Reply With Quote
  #6  
Old 01-14-2015, 10:45 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,947
Kyttias is on a distinguished road
Default

Nice! I also added an item rarity to my site. It has little use right now, but combined with a shop loyalty system, I'll be withholding some items from shops until a user has 'levelled up' a shop, thus, rarer items will be in shops after a user has gained enough shop loyalty. I'll also be having item capsule ball machines and drop chances while exploring, these effected by arrays of different rarities of items. ^^
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #7  
Old 01-15-2015, 01:29 AM
MikiHeart's Avatar
MikiHeart MikiHeart is offline
Premium Member
 
Join Date: Apr 2009
Posts: 187
Gender: Female
Credits: 20,326
MikiHeart
Default

Yes, I saw that in your thread! I love that idea so much.
I also love the capsule ball machines. Gacha as they call it in Japan.

I want to have items drop as well, but I want to make it so they have to claim it. So that people can't use refreshers or auto scripts and stuff.

I also want to work on adding a stocking and restocking system for my stores.

My site is all to do with collecting you see XD Collecting pets, and items, and all kinds of goodies. Because I love collecting when it comes to websites.
Reply With Quote
  #8  
Old 01-15-2015, 07:52 AM
MikiHeart's Avatar
MikiHeart MikiHeart is offline
Premium Member
 
Join Date: Apr 2009
Posts: 187
Gender: Female
Credits: 20,326
MikiHeart
Default

I'm trying to build a custom page, but it kinda breaks the theme. It makes the background on the default theme white, and in the bootstrap one, it changes the theme colours around (To colours that are in the theme, but different ones) and it makes the text bigger.

test.php
Code:
<?php


class TestController extends AppController{
	
	public function index(){
	   $mysidia = Registry::get("mysidia");

	}
}
?>
testview.php
Code:
<?php

class TestView extends View{
    
	
	public function index(){
	    $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle("Test");
        $document->add(new Comment("Test"));
		
	}
}
?>
Edit: I don't get it. It's the same as in blank.php and blackview.php (Not sure why misspelled..) Changing blackview.php to blankview.php and adding a title and the theme works fine..

Last edited by MikiHeart; 01-15-2015 at 07:56 AM.
Reply With Quote
  #9  
Old 01-15-2015, 09:54 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,947
Kyttias is on a distinguished road
Default

Well, it definitely shouldn't be misspelled. The view should match the controller. Blank always gave me troubles, too... I ended up using the Donate page as my base - it also helped me understand how form data was being tossed from the view to control and back.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #10  
Old 01-15-2015, 11:07 PM
MikiHeart's Avatar
MikiHeart MikiHeart is offline
Premium Member
 
Join Date: Apr 2009
Posts: 187
Gender: Female
Credits: 20,326
MikiHeart
Default

It's weird, because the blank page actually works. It's weird.

I will try the donate page as a base. If it still doesn't work, I'll post a new topic and hopefully HoF can give some insight.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeking Advanced PHP Coder (PAID) SoubisSacrifice Staff Central 14 01-29-2015 10:42 AM
Seeking a coder + artists~ Pear Staff Central 14 07-06-2014 03:42 PM
I need basic coding help Moontides Feedback and Suggestions 23 05-28-2014 01:54 PM
Seeking Mysidia coder Solistia Staff Central 4 05-03-2011 04:19 AM
My BASIC programs SleepWalker Other Chat 0 04-05-2010 08:37 AM


All times are GMT -5. The time now is 07:32 AM.

Currently Active Users: 456 (0 members and 456 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636